Mysql – INSERT … SELECT on a huge MySQL table

insertMySQLselect

I have isolated MySQL 5.5 with a huge table inside ( 3.5TB of data and yes, it is only 1 table ).

The goal is to copy a half of this table into another one on the same server. How to do that better and quicker? :

1) Just INSERT INTO new_table SELECT * FROM old_table WHERE ....
What will be MySQL behavior in this case? I expect that connection to MySQL will be broken by time out, however the query itself should run until all data are copied.
Or the MySQL will be just crashed with such query?

2) Using the same INSERT ... SELECT but selecting by chunks ( for example by 10000 rows). This should be definitely safer but much slower I guess.

What is the best way? Thank you in advance!

P.S. Before the insertion I will drop FK and indexes on new table + disable sql_log_bin and

Best Answer

Your option 2 will be the way to go, smaller chunks. Depending on the size of your rows, You could increase the rows to around 1M.