Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script for simple creation of an user including database
#!/bin/bash
PASS=`pwgen -s 40 1`
USER=`pwgen -B 10 1`
mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE $USER;
CREATE USER '$USER'@'localhost' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON $USER.* TO '$USER'@'localhost';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
echo "MySQL user created."
echo "Username: $USER"
echo "Password: $PASS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment