Created
May 4, 2016 14:02
-
-
Save danilostrazzullo/94e96635cc534320b43bb03de1f4ee37 to your computer and use it in GitHub Desktop.
Import a large sql dump file to a MySQL database from command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Import a large sql dump file to a MySQL database from command line | |
# https://cmanios.wordpress.com/2013/03/19/import-a-large-sql-dump-file-to-a-mysql-database-from-command-line/ | |
# store start date to a variable | |
imeron=`date` | |
echo "Import starting..." | |
dumpfile="/path/to/dumpfile.sql" | |
ddl="set names utf8; " | |
ddl="$ddl set global net_buffer_length=1000000;" | |
ddl="$ddl set global max_allowed_packet=1000000000; " | |
ddl="$ddl SET foreign_key_checks = 0; " | |
ddl="$ddl SET UNIQUE_CHECKS = 0; " | |
ddl="$ddl SET AUTOCOMMIT = 0; " | |
# if your dump file does not create a database, select one | |
ddl="$ddl USE db_name; " | |
ddl="$ddl source $dumpfile; " | |
ddl="$ddl SET foreign_key_checks = 1; " | |
ddl="$ddl SET UNIQUE_CHECKS = 1; " | |
ddl="$ddl SET AUTOCOMMIT = 1; " | |
ddl="$ddl COMMIT ; " | |
echo "Ready to import..." | |
echo "Importing. Please wait..." | |
mysql -h 127.0.0.1 -u root -p'yourPassword' -e "$ddl" | |
# store end date to a variable | |
imeron2=`date` | |
echo "------------" | |
echo "Start import: $imeron" | |
echo "End import: $imeron2" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment