$7.5

How To Create a New User and Grant Permissions in MySQL

Ask a question+
4

I set up a project on the remote server and need to configure database parameters; for that, I want to create a separate user and give him access only to one database. Please tell me how to create a new user and give whole access to him.

add comment

1 Answer

3

To create new user within the MySQL shell you need to run:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

To provide user whole access to your database run:
GRANT ALL PRIVILEGES ON myDatabase. * TO 'newuser'@'localhost';

You can also provide access to the single table:
GRANT ALL PRIVILEGES ON myDatabase.myTable TO 'newuser'@'localhost';

If you want to provide access to whole databases you can run:
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

After that be sure to reload all the privileges.
FLUSH PRIVILEGES;

For more details check here

add comment

Your Answer