0

I have a file (insert.sql) which has 250k rows like these with no key, no index :

INSERT `project_383`.`entity_metrics_build_1` VALUES ('d402afeb4630267f383b99875f37162d', 'ClMaxCycl', '-1');

INSERT `project_383`.`entity_metrics_build_1` VALUES ('d402afeb4630267f383b99875f37162d', 'ClLMethodsCalled', '0');

I input it to the my MyISAM table using mysql -u root -p project < insert.sql, the total time is 5 minutes.

I see in another thread, people say they can insert millions of rows under 1 seconds. I really don't understand. Can somebody explain for me why my SQL is so slow ?

My Server is 16gb Cpu xeon.

1
  • I would expect this is to do with MyISAM's table locking when inserting... but I can't be sure from looking at your queries they look pretty small.. Commented May 24, 2013 at 7:22

1 Answer 1

1

Combine them into a single INSERT with multiple VALUES clauses:

INSERT `project_383`.`entity_metrics_build_1`
VALUES ('d402afeb4630267f383b99875f37162d', 'ClMaxCycl', '-1'),
       ('d402afeb4630267f383b99875f37162d', 'ClLMethodsCalled', '0'),
       ...;

If you look at the file created by mysqldump, this is how it does it.

Sign up to request clarification or add additional context in comments.

1 Comment

Agreed. Or create a delimited data file and use LOAD DATA / mysqlimport.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.