Skip to content

Instantly share code, notes, and snippets.

@omeinusch
Created August 31, 2013 11:50
Show Gist options
  • Star 36 You must be signed in to star a gist
  • Fork 25 You must be signed in to fork a gist
  • Save omeinusch/6397770 to your computer and use it in GitHub Desktop.
Save omeinusch/6397770 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;
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"
@bcostea
Copy link

bcostea commented Jan 30, 2016

good one, thanks

@lucatze
Copy link

lucatze commented Apr 10, 2016

Thank you.

@ksaifullah
Copy link

So helpful. Thank you.

@askz
Copy link

askz commented May 16, 2017

Thanks!
I added just a line to prevent execution if errors are fired.
https://gist.github.com/askz/bee1e31e96e39b653cb77815ae664fa2

@MagePsycho
Copy link

Thanks for sharing.
I just developed one myself. Hope you find it helpful:
https://gist.github.com/MagePsycho/823070addf1764c91b86f258767a62d1

@BigBlue87
Copy link

I am new to scripting so please bear with me. I have created a script that installs httpd and mariadb but how do I get it so this part continues and creates database, user, etc automatically? my goal is to have the whole process of installing httpd, mariadb, and wordpress on my server automatically. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment