Skip to content

Instantly share code, notes, and snippets.

@faghani
Created February 9, 2020 15:09
Show Gist options
  • Save faghani/af1dd8095aaa176f4ac1e23609ff8cb3 to your computer and use it in GitHub Desktop.
Save faghani/af1dd8095aaa176f4ac1e23609ff8cb3 to your computer and use it in GitHub Desktop.
Import large sql file
#!/bin/sh
# store start date to a variable
imeron=`date`
echo "Import started: OK"
dumpfile="[SQL_PATH]"
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 [MYSQL_DATABASE]; "
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 "Import started: OK"
time mysql -h [MYSQL_HOST] -u [MYSQL_USER] -p[MYSQL_PASSWORD] -e "$ddl"
# store end date to a variable
imeron2=`date`
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