Skip to content

Instantly share code, notes, and snippets.

@willrnch
Last active August 29, 2015 14:07
Show Gist options
  • Save willrnch/b1cf588e6121b244b88f to your computer and use it in GitHub Desktop.
Save willrnch/b1cf588e6121b244b88f to your computer and use it in GitHub Desktop.
Create MySQL database with random user
#!/bin/bash
pass=`openssl rand -hex 12`
db=$1
if [ -z $1 ]; then
db=`openssl rand -hex 12`
fi
user=$db
echo "/*"
echo "db : $db";
echo "user : $user";
echo "pass : $pass";
echo "*/";
echo "\n";
echo "START TRANSACTION;";
echo "CREATE DATABASE \`$db\`;";
echo "CREATE USER '$user'@'%' IDENTIFIED BY '$pass';";
echo "GRANT ALL PRIVILEGES ON \`$db\`.* TO '$user'@'%';";
echo "COMMIT;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment