Skip to content

Instantly share code, notes, and snippets.

@epreston
Created June 27, 2021 11:08
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 epreston/c089f459273435bc9f7546bc465ef961 to your computer and use it in GitHub Desktop.
Save epreston/c089f459273435bc9f7546bc465ef961 to your computer and use it in GitHub Desktop.
create a quick mysql-user pair with strong password
#!/bin/bash
PASS=`pwgen -s 40 1`
mysql -uroot -p <<MYSQL_SCRIPT
CREATE DATABASE $1;
CREATE USER '$1'@'localhost' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON $1.* TO '$1'@'localhost';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
echo "MySQL user created."
echo "Username: $1"
echo "Password: $PASS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment