Last active
May 6, 2018 20:04
-
-
Save mikepsinn/c556646c70c4a3ec71c5b057eeab75e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "You can run from a gist using:" | |
| echo "curl https://gist.github.com/mikepsinn/c556646c70c4a3ec71c5b057eeab75e6/raw/147dc4386f8cc0c6a47e450997f4821e07845ceb/mysql_create_user.sh | bash -s ROOT_PASSWORD NEW_USER_PASSWORD" | |
| if [ ! -f ~/.my.cnf ]; | |
| then | |
| echo "ERROR: Please create ~/.my.cnf containing:" | |
| echo "[client]" | |
| echo "password=your_pass" | |
| exit 1 | |
| else | |
| echo "Using password from ~/.my.cnf" | |
| fi | |
| set -x #echo on | |
| export NEW_USER_NAME=quantimodo | |
| export NEW_USER_PASS=${1} | |
| export DATABASE_HOST=127.0.0.1 | |
| CREDENTIALS="sudo mysql --host=${DATABASE_HOST} --port 3306 -u root -e" | |
| ${CREDENTIALS} "GRANT ALL PRIVILEGES ON *.* TO '${NEW_USER_NAME}'@'%' IDENTIFIED BY '${NEW_USER_PASS}';" | |
| ${CREDENTIALS} "FLUSH PRIVILEGES;" | |
| mysql --host=${DATABASE_HOST} -u root ${TARGET_DB_NAME} << EOF | |
| GRANT SELECT ON *.* TO 'readonly'@'%' IDENTIFIED BY '${NEW_USER_PASS}'; | |
| FLUSH PRIVILEGES; | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment