Last active
August 29, 2015 14:07
-
-
Save willrnch/b1cf588e6121b244b88f to your computer and use it in GitHub Desktop.
Create MySQL database with random user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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