Skip to content

Instantly share code, notes, and snippets.

@seraphyn
Created February 27, 2019 07:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seraphyn/1e1f5c02fc3c2b4b119ca946952a42f4 to your computer and use it in GitHub Desktop.
Save seraphyn/1e1f5c02fc3c2b4b119ca946952a42f4 to your computer and use it in GitHub Desktop.
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