Skip to content

Instantly share code, notes, and snippets.

@bekce
Last active July 29, 2016 10:11
Show Gist options
  • Select an option

  • Save bekce/f5a24f56875afb572768222d26a1e362 to your computer and use it in GitHub Desktop.

Select an option

Save bekce/f5a24f56875afb572768222d26a1e362 to your computer and use it in GitHub Desktop.
#!/bin/sh
if [ $# -ne 4 ]
then
echo "Usage: <new-db-name> <new-user> <new-pass> <root-pass>"
exit 1
fi
dbname=$1
newuser=$2
newpass=$3
rootpass=$4
mysql -uroot -p$rootpass<<EOF
CREATE DATABASE IF NOT EXISTS $dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT USAGE ON * . * TO '$newuser'@'localhost' IDENTIFIED BY '$newpass' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
GRANT ALL PRIVILEGES ON $dbname . * TO '$newuser'@'localhost';
EOF
echo "database $dbname created, user $newuser with pass $newpass is granted permission"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment