Skip to content

Instantly share code, notes, and snippets.

@TiuTalk
Created January 25, 2013 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiuTalk/4634798 to your computer and use it in GitHub Desktop.
Save TiuTalk/4634798 to your computer and use it in GitHub Desktop.
#!/bin/sh
USER="root";
PASS="pass";
# Run a mysql command as root
mysqlcommand() {
echo "$@";
mysql -u"$USER" -p"$PASS" -e "$@";
}
# Create the database
mysqlcommand "CREATE DATABASE IF NOT EXISTS \`$1\` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;";
# Create the user
mysqlcommand "CREATE USER '$1'@localhost IDENTIFIED BY '$1';";
# Grant permissions
mysqlcommand "GRANT ALL PRIVILEGES ON \`$1\`.* TO '$1'@localhost WITH GRANT OPTION;";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment