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.
Contact Us