Last active
May 9, 2016 17:51
-
-
Save ad-m/cebd00b6da3ed8a8cf47 to your computer and use it in GitHub Desktop.
This file contains 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 | |
if [ -z "$1" ]; then | |
echo -n "Enter db_name: "; | |
read db_name; | |
exit; | |
else | |
db_name="$1"; | |
fi; | |
password=$(strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 15 | tr -d '\n'); | |
mysql --defaults-file=/etc/mysql/debian.cnf << EOF | |
CREATE USER '$db_name'@'localhost' IDENTIFIED BY '$password'; | |
CREATE DATABASE $db_name CHARACTER SET utf8 COLLATE utf8_polish_ci; | |
GRANT ALL PRIVILEGES ON $db_name.* TO '$db_name'@'localhost'; | |
FLUSH PRIVILEGES; | |
EOF | |
cat - << EOF | |
Host: localhost | |
User: $db_name | |
Password: $password | |
Database: $db_name | |
URL: mysql://$db_name:$password@localhost/$db_name | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment