Skip to content

Instantly share code, notes, and snippets.

@mattbell87
Forked from omeinusch/create-mysql.bash
Last active May 7, 2024 01:07
Show Gist options
  • Save mattbell87/1e678cc850e0ed66444b02a8cb6a094f to your computer and use it in GitHub Desktop.
Save mattbell87/1e678cc850e0ed66444b02a8cb6a094f to your computer and use it in GitHub Desktop.
Simple bash script to create mysql db, user with generated password
#!/bin/bash
echo "Creating MySQL user and database"
PASS=$2
if [ -z "$2" ]; then
PASS=`openssl rand -base64 8`
fi
mysql -u root <<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 and database created."
echo "Username: $1"
echo "Database: $1"
echo "Password: $PASS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment