How To Create a New User and Grant Permissions in MySQL

Ask a question+

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


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.

For more details check here

add comment

Your Answer