Skip to content

Instantly share code, notes, and snippets.

@kevinruscoe
Last active December 30, 2015 03:49
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 kevinruscoe/09f5edfe1fb6a3d1bef4 to your computer and use it in GitHub Desktop.
Save kevinruscoe/09f5edfe1fb6a3d1bef4 to your computer and use it in GitHub Desktop.
How to create a MySQL user and assign it to a databases.
# ~1~ = Datbase Name
# ~2~ = New MySQL username
# ~3~ = The new users password
# Create a database
CREATE DATABASE `~1~`;
# Create a user
CREATE USER '~2~'@'localhost' IDENTIFIED BY '~3~';
# Assign it the new database
GRANT ALL PRIVILEGES ON `~1~`.* TO '~2~'@'localhost';
# Reload privilegs
FLUSH PRIVILEGES;
# SAMPLE
CREATE DATABASE `DB_NAME`;
CREATE USER 'DB_USERNAME'@'localhost' IDENTIFIED BY 'DB_PASSWORD';
GRANT ALL PRIVILEGES ON `DB_NAME`.* TO 'DB_USERNAME'@'localhost';
FLUSH PRIVILEGES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment