Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move million records from MEMORY table to MYISAM table

I am looking for a fast way to move records from a MEMORY table to MYISAM table. MEMORY table has around 0.5 million records. Both tables have exactly the same structure (same number of columns, data types etc.). But the MYISAM table is indexed (B-TREE) on a few columns. There are around 25 columns most of which are unsigned integers.

I have already tried using "INSERT INTO SELECT * FROM " query. But is there any faster way to do this?

Appreciate your help.

Prashant

like image 729
Prashant Avatar asked Nov 15 '22 11:11

Prashant


1 Answers

A others pointed out -- you should not use indexes during insert. You can disable updating them on every insert:

ALTER TABLE table DISABLE KEYS;
INSERT INTO table
ALTER TABLE tbl_name ENABLE KEYS;

And also lock a table to get single index write:

LOCK TABLES table WRITE;
INSERT INTO table
UNLOCK TABLES;

Anyway, if you use it in a single INSERT ... SELECT you might not get significant performance gain.

You can also tune bulk_insert_buffer_size setting in the server config.

More on: http://dev.mysql.com/doc/refman/5.0/en/insert-speed.html

like image 157
Daniel Bauke Avatar answered Jan 13 '23 22:01

Daniel Bauke