Created
December 2, 2015 13:13
-
-
Save thepaksgist/92ff5eb1cfb3b0b5e501 to your computer and use it in GitHub Desktop.
Bash / Shell Script for import all MySQL database
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=/usr/bin/mysql | |
MYSQL_PASSWORD="XXXXX" | |
IP="localhost" | |
for db in *.gz | |
do | |
DB_NAME=$(echo $db | cut -f 1 -d '.') | |
#echo $db | |
#echo $DB_NAME | |
#break; | |
#$MYSQL -u$MYSQL_USER -e "create database $db_name" | |
SQL="create database $DB_NAME;GRANT ALL PRIVILEGES ON $DB_NAME.* TO $MYSQL_USER@$IP IDENTIFIED BY '$MYSQL_PASSWORD';FLUSH PRIVILEGES;" | |
mysql -u root -p$MYSQL_PASSWORD -e "$SQL" | |
if [ $? != "0" ]; then | |
echo "[Error]: Database creation failed" | |
#exit 1 | |
else | |
zcat $db | $MYSQL -u$MYSQL_USER -p$MYSQL_PASSWORD $DB_NAME | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment