How to create a New Database-user and Grand Permissions – MySQL

We already discussed about the creation of MySQL DB and DB users. Here I am explaining the commands which are using to Grand Privileges to users for accessing the Databases in your server.

Enter the mysql prompt by following the step below:

# mysql -u root -p

It then prompts for password. Enter the MySQL root password.

Example:

root@server [/]# mysql -u root -p
Enter password:

1, Command to Grand All privileges on DB for a user.

mysql> GRANT ALL PRIVILEGES ON database.* to 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

Refer the example below for more details:

mysql> GRANT ALL PRIVILEGES ON crybit_wp.* to 'crybit_wp'@'localhost' IDENTIFIED BY 'with_the_new_password' WITH GRANT OPTION;

2, how to add SELECT privileges to a user using GRANT.

mysql> GRANT SELECT ON database.* to 'username'@'localhost' IDENTIFIED BY 'password';

3, how to add a selection of privileges to a user using GRANT.

mysql> GRANT SELECT, INSERT, DELETE ON database.* to 'username'@'localhost' IDENTIFIED BY 'password';

That’s it 🙂 🙂

Related:
How to create/restore MySQL dump/backup of all the databases.
How to create a database and database user from command line
Reset mysql root password from command line
How to allow mysql client to access remote mysql databases

Post navigation

Arunlal A

Senior System Developer at Zeta. Linux lover. Traveller. Let's connect! Whether you're a seasoned DevOps pro or just starting your journey, I'm always eager to engage with like-minded individuals. Follow my blog for regular updates, connect on social media, and let's embark on this DevOps adventure together! Happy coding and deploying!

One thought on “How to create a New Database-user and Grand Permissions – MySQL

  1. It is important to have the database and that is why the creating the database is also necessary and for this, a user has to be skilled and also to make the grand permissions on the MySql is important to have. There are many processes by which a database can be created and the given process can also be applied.

Leave a Reply

Your email address will not be published. Required fields are marked *