Today I had to import a very large SQL dump file (6 Gb) to a MySQL database using windows command line. If you are using linux it is the same. The process is the following:
- Open a command prompt (or shell in Linux) with administrative privilleges
- If you are in Windows set character set to unicode. Linux is using UTF-8 by default.
1chcp 65001 - Connect to a mysql instance using command line
if you are in localhost you do not need host and port
1$PATH_TO_MYSQL\mysql.exe -h 192.168.1.1 --port=3306 -u root -p1$PATH_TO_MYSQL\mysql.exe -u root -p - You are now in mysql shell. Set network buffer length to a large byte number. The default value may throw errors for such large data files
1set global net_buffer_length=1000000; - Set maximum allowed packet size to a large byte number.The default value may throw errors for such large data files.
1set global max_allowed_packet=1000000000; - Disable foreign key checking to avoid delays,errors and unwanted behaviour
1 2 3SET foreign_key_checks = 0; SET UNIQUE_CHECKS = 0; SET AUTOCOMMIT = 0; - Import your sql dump file
You are done! Remember to enable foreign key checks when procedure is complete!
1source C:\bob_db\dbdump150113.sql1 2 3SET foreign_key_checks = 1; SET UNIQUE_CHECKS = 1; SET AUTOCOMMIT = 1;
If you are in Linux you can create a Bash script which will do the dirty job and write to stdout start and end time of import:
|
|