Skip to content

Instantly share code, notes, and snippets.

@alejandrofloresm
Last active January 2, 2019 20:26
Show Gist options
  • Save alejandrofloresm/a886b7b83d07475e69d8a54df425c6cb to your computer and use it in GitHub Desktop.
Save alejandrofloresm/a886b7b83d07475e69d8a54df425c6cb to your computer and use it in GitHub Desktop.
Generate and grant new permissions to a MySQL user to a new database
/**
* 1. Create the database
* Change:
* <database_name>: to your database name
*/
CREATE DATABASE <database_name>;
/**
* 2. Create the user
* Change:
* <username> to your username
* <server:localhost>
* <your_password> to your password
*/
CREATE USER '<username>'@'<server:localhost>' IDENTIFIED BY 'your_password';
/**
* 3. Set the priviliges and finally flush the priviliges
* Change:
* <username> to your username
* <server:localhost>
* The ...ON '<database_name>'.* TO... the * is for all the tables
*/
GRANT ALL PRIVILEGES ON <database_name>.* TO '<username>'@'<server:localhost>';
FLUSH PRIVILEGES;
/**
* No comments section
*/
CREATE DATABASE <database_name>;
CREATE USER '<username>'@'<server:localhost>' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON <database_name>.* TO '<username>'@'<server:localhost>';
FLUSH PRIVILEGES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment