Created
October 18, 2021 15:53
-
-
Save icyz/dcb8389ab13249ae3744d70e6b8a8b3b to your computer and use it in GitHub Desktop.
Restore mysql dump using bash script
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/bash | |
# How to use: bash mysqlrestore.sh DATABASENAME /path/to/dump.sql | |
########################## | |
MPATH="/bin/" | |
HOST="127.0.0.1" | |
USER="root" | |
PASS="root" | |
########################## | |
# Colors | |
BLACK=$(tput setaf 0) | |
RED=$(tput setaf 1) | |
GREEN=$(tput setaf 2) | |
YELLOW=$(tput setaf 3) | |
LIME_YELLOW=$(tput setaf 190) | |
POWDER_BLUE=$(tput setaf 153) | |
BLUE=$(tput setaf 4) | |
MAGENTA=$(tput setaf 5) | |
CYAN=$(tput setaf 6) | |
WHITE=$(tput setaf 7) | |
BRIGHT=$(tput bold) | |
NORMAL=$(tput sgr0) | |
BLINK=$(tput blink) | |
REVERSE=$(tput smso) | |
UNDERLINE=$(tput smul) | |
printf "\n\n${RED}Delete $1\n================================\n${NORMAL}" | |
${MPATH}mysqladmin -h "${HOST}" -u "${USER}" "-p${PASS}" drop "$1" | |
printf "\n\n${GREEN}Create $1\n================================\n${NORMAL}" | |
${MPATH}mysql -u "${USER}" "-p${PASS}" << EOF | |
CREATE DATABASE $1 COLLATE 'utf8_unicode_ci'; | |
GRANT ALL PRIVILEGES ON *.* TO '${USER}'@'${HOST}'; | |
FLUSH PRIVILEGES; | |
EOF | |
printf "\n\n${CYAN}Load $1 < $2\n================================\n${NORMAL}" | |
${MPATH}mysql -f -h "${HOST}" -u "${USER}" "-p${PASS}" "$1" < "$2" | |
printf "\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment