If you have a schema already in place, you should use mysqldump options to create the dump of the data to perform in the inserts only
mysqldump -h... -u... -p... --no-create-info --databases ... > MySQLData.sql
You should also make sure to raise the bulk_insert_buffer_size (default is 8M) on all DB Servers to accommodate large extended inserts. This will also help LOAD DATA INFILE if loading non-empty tables.
You are going to have to also adjust your max_allowed_packet (default is 1M).
Try these settings for starters:
[mysqld]
max_allowed_packet=256M
bulk_insert_buffer_size=256M
UPDATE 2011-10-11 06:53 EDT
Regardless of how beefy the hardware is, how much RAM you have allocated, how well tuned the OS is, and how current the version of MySQL is, MySQL will only perform as well as it is configured.
Example: If you have a swimming pool that can hold 10,000 gallons of water, you have a truck holding 10,000 gallons of water, and the hose on the truck is only as big as a straw, you can only push but so much water through the straw to fill the pool. Getting a bigger truck or getting a faster water pump simply will not improve things. You must exchange the hose for a much bigger hose to accommodate more water, thus, more throughput.
In like fashion, MySQL 5.5 out-of-the-box does not come fully tuned.
Example #1: MySQL 5.5 comes with semisynchronous replication. By default, it is disabled. You must do the two step process of starting mysql, runnning INSTALL PLUGIN on master and slave modules, shutdown mysql, add timing and activation options to my.cnf for the semisych features, then starting up mysql for the second time. Only then will semisync replication work.
Example #2: The bulk insert buffer by default is 8M. The bulk insert buffer will not grow because of the presence of any specific hardware or software. It stays 8M until you increase it. It is possible to increase it by either adding it to my.cnf and restarting mysql or running SET bulk_insert_buffer_size = 268435456;
to set it to 256M within a session and then load the mysqldump within that same session.
Example #3: MySQL 5.5 is fully capable of engaging multiple CPUs. By default, the features for engaging multiple CPUs is disabled. They require tuning because although MySQL 5.5 is multicore ready, MySQL 5.5 is only as multithreaded as you configure it.
Conclusion: You must configure MySQL to recognize that it has beefy hardware, more RAM, and a cooperative OS at its disposal.
When I asked Question 4: (During the ENABLE KEYS phase, do you see Repair by keycache in SHOW PROCESSLIST?) this is what happens when there is no more room for sorting. You most likely ran out of room if mysqld attempted to switch to Repair by keycache
.
If you are stuck with this 2GB Server for testing, try one or more of the following:
- Lower bulk_insert_buffer_size to 64M
- mysqldump the original data using --skip-extended-insert and reload with it. It will produce one INSERT per row. It will be slower to reload (about 2-3 timer longer) but at least memory will be spared collateral damage
- Abandon doing
DISABLE KEYS
and ENABLE KEYS
Best Answer
There are some rare occasions when mysqld processes
ALTER TABLE ... ENABLE KEYS;
and you getRepair by keycache
. The real question to ask is Under what circumstances does mysqld performRepair by keycache
?According to MySQL Documentation on General Thread States
There are one or more server variables in the session that could potentially affect this behavior
1M
, MinValue:64K
, MaxValue:64M
Repair by sorting
and switch toRepair by keycache
.SUGGESTION
Based on the MySQL Documentation on sort_buffer_size
Only sort_buffer_size and myisam_sort_buffer_size can be changed for the session.
If you don't have a lot of memory, change myisam_sort_buffer_size so that a larger temp table can be formed. To set it to 1G in your session, do one of the following before executing a large reindexing:
or
That way, the temp table on disk will be allowed to grow to 1G. Make sure the folder mapped to tmpdir can hold large temp tables.
If you want 1G as the permanent setting for myisam_sort_buffer_size going forward, do this
STEP #1 : Add this to
/etc/my.cnf
This will allow connections to have this setting after mysqld is restarted.
STEP #2 : Login to mysql as
root@localhost
and runThis will enabled new connections to have this setting. Current connections would have to be closed and reopened (perhaps restarting
apache/tomcat/Hibernate
or whatever web server you are using).MY OTHER POSTS ON
Repair by keycache
May 09, 2012
: ENABLE KEYS on a large table is crashing mysqlMay 17, 2013
: MySQL Hanging Completely when `ALTER TABLE... ENABLE KEYS`Aug 12, 2013
: MySQL MyISAM index causes query to match no rows; indexes disabled, rows match