Last active
October 4, 2018 06:19
-
-
Save lonly197/9a118c16fbd956a9ae388073cf4eded3 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 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 | |
# store start date to a variable | |
imeron=`date` | |
echo "Import started: OK" | |
# set sql dump file | |
dumpfile="/home/lonly/big.sql" | |
ddl="set names utf8; " | |
# set network buffer length to a large byte number | |
ddl="$ddl set global net_buffer_length=1000000;" | |
# set maximum allowed packet size to a large byte number | |
ddl="$ddl set global max_allowed_packet=1000000000; " | |
# disable foreign key checking to avoid delays,errors and unwanted behaviour | |
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 testdb; " | |
# import your sql dump file | |
ddl="$ddl source $dumpfile; " | |
# remember to enable foreign key checks when procedure is complete! | |
ddl="$ddl SET foreign_key_checks = 1; " | |
ddl="$ddl SET UNIQUE_CHECKS = 1; " | |
ddl="$ddl SET AUTOCOMMIT = 1; " | |
ddl="$ddl COMMIT ; " | |
echo "Import started: OK" | |
# setting the host and user | |
time mysql -h 127.0.0.1 -u root -proot -e "$ddl" | |
# store end date to a variable | |
imeron2=`date` | |
# print time | |
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