Created
November 21, 2024 08:31
-
-
Save fbakhda/bace9acf13b3e597c1aee97478677b9e to your computer and use it in GitHub Desktop.
MySQL DB Restore script with Param 1: Database Name Param 2: Database SQL Filepath
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/bash | |
MYSQL_USER="root" | |
MYSQL_PASSWORD="" # Change this to your db password | |
function restore() { | |
( | |
echo "SET AUTOCOMMIT=0;" | |
echo "SET UNIQUE_CHECKS=0;" | |
echo "SET FOREIGN_KEY_CHECKS=0;" | |
cat $2 | |
echo "SET FOREIGN_KEY_CHECKS=1;" | |
echo "SET UNIQUE_CHECKS=1;" | |
echo "SET AUTOCOMMIT=1;" | |
echo "COMMIT;" | |
) | mysql -u"$MYSQL_USER" -p"$MYSQL_PASSWORD" --default-character-set=utf8 "$1" | |
} | |
restore $1 $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mysql-db-restore.sh [database-name] [database-sql-filepath]