Skip to content

Instantly share code, notes, and snippets.

@ad-m
Last active May 9, 2016 17:51
Show Gist options
  • Save ad-m/cebd00b6da3ed8a8cf47 to your computer and use it in GitHub Desktop.
Save ad-m/cebd00b6da3ed8a8cf47 to your computer and use it in GitHub Desktop.
#!/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