Skip to content

Instantly share code, notes, and snippets.

@edwinvelez
Created December 26, 2020 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwinvelez/9f534d6d22ec2fde65039574f9e483d8 to your computer and use it in GitHub Desktop.
Save edwinvelez/9f534d6d22ec2fde65039574f9e483d8 to your computer and use it in GitHub Desktop.
Create database and grant user access via bash script.
#! /bin/bash
newUser=''
newDbPassword=''
newDb=''
host=localhost
#host='%'
commands="CREATE DATABASE \`${newDb}\`;CREATE USER '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT USAGE ON *.* TO '${newUser}'@'${host}' IDENTIFIED BY '${newDbPassword}';GRANT ALL privileges ON \`${newDb}\`.*
TO '${newUser}'@'${host}';FLUSH PRIVILEGES;"
echo "${commands}" | /usr/bin/mysql -u root -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment