I need to copy a large (80 mil records) MySQL table into another table as I need to add an index to the table and using ALTER would just be too slow / run out of RAM.
I’ve tried running a MySQL script containing INSERT INTO table2 SELECT * FROM table1 in a screen instance so that I can detach and exit the SSH session, but for some reason it did the first 20 million rows (which took a couple of hours) and then it randomly stopped. Would this method require a lot of memory? How else can I do this fast and in the background?
Dump the table into a .csv file
Create a new table with the proper schema
Then load the new table with the .csv data in it
FYI: these commands aren’t tested and may need some adjusting, but you should get the idea