Skip to content

Instantly share code, notes, and snippets.

@Wieljer
Forked from omeinusch/create-mysql.bash
Last active September 4, 2022 00:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Wieljer/5305f33e7a48c97e4136cee5597d23cf to your computer and use it in GitHub Desktop.
Save Wieljer/5305f33e7a48c97e4136cee5597d23cf to your computer and use it in GitHub Desktop.
Simple non-interactive bash script to create mysql db, user with generated password.
#!/bin/bash
PASS=$(pwgen -s 15 1)
USER="CDRT"
DB="drupal"
service mysqld start
mysql -uroot <<MYSQL_SCRIPT
CREATE DATABASE $DB;
CREATE USER '$USER'@'localhost' IDENTIFIED BY '$PASS';
GRANT ALL PRIVILEGES ON $DB.* TO '$USER'@'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