Skip to content

Instantly share code, notes, and snippets.

@gnh1201
Forked from omeinusch/create-mysql.bash
Last active March 9, 2018 04:39
Show Gist options
  • Save gnh1201/ca554c5568f9b8392cebd78e1166f469 to your computer and use it in GitHub Desktop.
Save gnh1201/ca554c5568f9b8392cebd78e1166f469 to your computer and use it in GitHub Desktop.
Simple bash script to create mysql db, user with generated password
#!/bin/bash
PASS=`pwgen -s 40 1`
mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE $1 default character set utf8 COLLATE utf8_general_ci;
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