Skip to content

Instantly share code, notes, and snippets.

@dgoguerra
Last active December 19, 2016 12:12
Show Gist options
  • Save dgoguerra/2a335b8c70cc692dab35d19928455a3b to your computer and use it in GitHub Desktop.
Save dgoguerra/2a335b8c70cc692dab35d19928455a3b to your computer and use it in GitHub Desktop.
Create database and setup credentials
#!/usr/bin/env bash
bin="mysql"
#bin="/Applications/MySQLWorkbench.app/Contents/MacOS/mysql"
database=$1
username=$2
password=$3
if [ ! "$password" ]; then
echo "usage: DB_HOST= DB_USER= DB_PASSWORD= command <database> <username> <password>"
exit 1
fi
"$bin" -h"$DB_HOST" -u"$DB_USER" -p"$DB_PASSWORD" <<EOF
create database if not exists $database;
grant all on $database.* TO '$username'@'%' identified by '$password';
flush privileges;
EOF
@dgoguerra
Copy link
Author

See created user accounts:

select concat(quote(user),'@',quote(host)) UserAccount from mysql.user;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment