Skip to content

Instantly share code, notes, and snippets.

@cirocosta
Last active August 29, 2015 13:56
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 cirocosta/9316904 to your computer and use it in GitHub Desktop.
Save cirocosta/9316904 to your computer and use it in GitHub Desktop.
Creating a user with Mysql CLI

quick snippet for creating a user w/ mysql cli.

First, login and create a user:

$ mysql -u root_user -p
mysql > CREATE USER 'username'@'place' IDENTIFIED BY 'password';

then, grant privileges to it. The syntax is as follows:

GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’

Now, create a database so that the user will be able to manage it:

mysql> CREATE DATABASE database_name;

Now, in our case, apply:

mysql> GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'place';

Finally, execute flush to reload internal caches and the grant tables (you must have RELOAD permission).

mysql> FLUSH PRIVILEGES;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment