How to speed up execution of mysql INSERT statements

A very good approach to speed up the execution of an INSERT statement
is to temporarly disable the keys (when executing your query), this
will help MySQL to concetrate on the INSERT and not building indexes at the same
time. Also you should LOCK your tables.

The basic syntax of such a simple operation is listed below:

ALTER TABLE table_name DISABLE KEYS;

LOCK TABLES table_name WRITE;

LOAD DATA INFILE file_name INTO TABLE table_name

UNLOCK TABLES;

ALTER TABLE table_name ENABLE KEYS;

Advertisement

No comments yet

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.