How To Create a New User and Grant Permissions in MySQL

About MySQL

MySQL is an open-source relational database management software (RDBMS) that helps users store, organize, and later retrieve data.

How to Create a New User

A new user can be created within the MySQL shell, using the following statement:

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

This will create a new user named ‘newuser’ without any permissions.

To give full access to all databases for the new user, run the following statement:

GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

Then run following statement to reload all the privileges:

FLUSH PRIVILEGES;

To give access to a specific database for the new user, run the following statement:

GRANT ALL PRIVILEGES ONĀ database . * TO 'newuser'@'localhost';

To revoke access:

REVOKEĀ ALL PRIVILEGES ON database.* FROM 'newuser'@'localhost';

Drop a MySQL user:

DROP USER 'newuser'@'localhost';

Have something to Add?

Loading Facebook Comments ...
Loading Disqus Comments ...