Skip to content

Instantly share code, notes, and snippets.

@tsuyo
Created October 4, 2021 11:54
Show Gist options
  • Save tsuyo/88de5391f94c2249ba5d463302047596 to your computer and use it in GitHub Desktop.
Save tsuyo/88de5391f94c2249ba5d463302047596 to your computer and use it in GitHub Desktop.
Create a MySQL Database
usage() {
echo "Usage: $0 <DB_NAME> <DB_USER> <DB_PASSWORD>"
exit
}
DB_NAME=$1
DB_USER=$2
DB_PASSWORD=$3
[ -z "${DB_NAME}" -o -z "${DB_USER}" -o -z "${DB_PASSWORD}" ] && usage
mysql -u root -p << EOF
drop database if exists ${DB_NAME};
create database ${DB_NAME} character set 'utf8';
use ${DB_NAME};
grant all on ${DB_NAME}.* to ${DB_USER}@localhost identified by '${DB_PASSWORD}';
flush privileges;
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment