stored procedures - How to loop through and copy every row of large MySQL table? -


scenario:

i have mysql myisam table (table1) 11 million rows, of want copy better table (table2, has innodb engine along proper indices). since adding indexes myisam table takes long want loop through entire table , copy every row new table.

is there way within mysql?

conditions:

  • there no time limit action (could looped "slowly").
  • the tables have same columns.
  • table1 online , needs stay online (being read time; i've temporarily paused writing).

problems:

  • mysql server shared host (no file system access).
  • mysqldump times out.
  • adding index times out.
  • simply inserting select of previous table times out.

idea:

perhaps 1 loop mysql statement, doing 10 000 @ time or that?

this works 1 (1) record:

insert products_indexed select * products products.p_product_id=(     select products.p_product_id id products     left outer join products_indexed on (         products.p_product_id = products_indexed.p_product_id     )     products_indexed.p_product_id null     limit 1 ) 

this looped using stored procedure:

begin declare x  int;  set x = 1;  while x  <= 1000000 set  x = x + 1;   insert products_indexed select * products products.p_product_id=(     select products.p_product_id id products     left outer join products_indexed on (         products.p_product_id = products_indexed.p_product_id     )     products_indexed.p_product_id null     limit 1 );  end while;  end 

this not best way loop through, it's try. seems work, how optimize it? (perhaps query couple of thousand rows , inserts?

http://dev.mysql.com/doc/refman/5.7/en/converting-tables-to-innodb.html

to convert non-innodb table use innodb use alter table:  alter table table_name engine=innodb; 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -