Skip to content

Instantly share code, notes, and snippets.

@askz
Forked from omeinusch/create-mysql.bash
Created May 16, 2017 17:58
Show Gist options
  • Save askz/bee1e31e96e39b653cb77815ae664fa2 to your computer and use it in GitHub Desktop.
Save askz/bee1e31e96e39b653cb77815ae664fa2 to your computer and use it in GitHub Desktop.
Simple bash script to create mysql db, user with generated password
#!/bin/bash
# The script will fail at the first error encountered
set -e
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"
@ddavaham
Copy link

ddavaham commented Jan 8, 2018

Sweetness. Thanks

@alabius
Copy link

alabius commented Mar 13, 2018

Please can this also be used to create tables for database and import csv

@ichux
Copy link

ichux commented Aug 8, 2020

Please can this also be used to create tables for database and import csv

You should be able to do that. Did you try it out yet?

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