Dump a MySQL database to file
bash
1mysqldump -u username -p database_name > data-dump.sqlImport a MySQL database from file
bash
1mysql -u username -p new_database < data-dump.sqlFor quick large MySQL database import use:
Manual mode by copy paste in terminal.
Start of file
bash
1sed -i '1s/^/SET autocommit = 0;\n/' dump.sqlEnd of file
bash
1echo 'COMMIT;' >> dump.sqlOr create bash script to run the above commands.
bash
1#!/bin/bash2# Check if filename is provided as argument3if [ $# -eq 0 ]; then4 echo "Usage: $0 <filename>"5 exit 16fi7
8filename=$19
10# Add 'SET autocommit = 0;' at the beginning of the file11sed -i '1s/^/SET autocommit = 0;\n/' "$filename"12
13# Append 'echo 'COMMIT;' to the end of the file14echo 'COMMIT;' >> "$filename"15
16echo "Now import it. quickly :)"