Grant Permissions

Use the GRANT statement to grant privileges to the user. Specify the privileges and the database or tables they apply to. Replace username and database_name with appropriate values.

1. To grant privileges only for our database.

GRANT SELECT, INSERT, UPDATE ON database_name.* TO 'username'@'localhost';

Explanation:

  • SELECT, INSERT, UPDATE, etc: Replace these with the privileges we want to grant.
  • database_name: Replace this with the name of the database. we can also specify a table instead of * to grant privileges for specific tables.

Example: Suppose we are granting select and insert operations to the user minal.

GRANT SELECT, INSERT ON mydb.* TO 'minal'@'localhost';

2. To grant all privileges to user.

GRANT ALL PRIVILEGES ON *.* TO 'username'@localhost IDENTIFIED BY 'userpassword';

The database or table that the user has access to is denoted by the *.* in the sentence. This particular command gives access to every database on the server. we should change the symbol to the name of the database we are granting access to, as this might be a serious security risk.

Replace the username and userpassword with the desired username and password of the new user. By using this syntax we can provide all the access to all databases or table stores on the MariaDB server to the user identified by the password.

How to Create User With Grant Privileges in MariaDB

In database management, effective user management and privilege assignment are important for secure and efficient operations. MariaDB, a popular open-source relational database management system, offers robust features for managing users and their access rights.

In this article, we will understand how to create users and grant privileges to them in MariaDB with the help of various examples.

Similar Reads

How to Create User and Grant Privileges?

To manage users in MariaDB, we need to understand how to create users and grant them appropriate privileges. Let’s understand step-by-step instructions and examples....

Connect to MariaDB

Use the MariaDB client or command–line interface to connect to the MariaDB server. Let’s Enter the password and access the MariaDB client....

Create a User

Once we are connected to the MariaDB server, use the CREATE USER statement to create a new user. Replace the username and password with the desired username and password for the new user....

Grant Permissions

Use the GRANT statement to grant privileges to the user. Specify the privileges and the database or tables they apply to. Replace username and database_name with appropriate values....

Reload Privileges

After granting privileges, we need to reload the privileges for the changes to take effect. we have to enter the following command each time we run a command on the MariaDB server....

Remove MariaDB User Account

If we need to remove a user, we can use the DROP statement:...

Conclusion

Overall, Assigning rights and privileges for your users also plays a big role in protecting the security and safety of your MariaDB databases. By implementing what you have read in this article and keeping in mind the right practices, you will offer users necessary access while also protecting the sensitive data from external users. Frequently monitoring and updating user privileges is a necessary step to keep the security environment healthy through changes in security requirements and consistent database environment....

Contact Us