Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Tuesday, 20 February 2024

GRANT and REVOKE in MARIADB

In MariaDB, which is a fork of MySQL, GRANT and REVOKE statements are used similarly to MySQL for managing user privileges and permissions on database objects.


 GRANT:


The GRANT statement is used to give specific privileges to users or roles.

Syntax:


GRANT privileges

    ON object

    TO user [IDENTIFIED BY 'password']

    [WITH GRANT OPTION];


Example:


GRANT SELECT, INSERT ON employees

    TO 'user1'@'localhost' IDENTIFIED BY 'password';


This grants the SELECT and INSERT privileges on the employees table to the user user1 with the password 'password'.


GRANT SELECT ON employees.*

    TO 'HR'@'localhost' WITH GRANT OPTION;


This grants the SELECT privilege on all columns of the employees table to the user HR with the option to further grant this privilege to other users.


 REVOKE:


The REVOKE statement is used to take back privileges that have been granted from users or roles.


Syntax:


REVOKE privilege

    ON object

    FROM user;


Example:


REVOKE SELECT, INSERT ON employees

    FROM 'user1'@'localhost';


This revokes the SELECT and INSERT privileges on the employees table from the user user1.


REVOKE SELECT ON employees.*

    FROM 'HR'@'localhost';


This revokes the SELECT privilege on all columns of the employees table from the user HR.


Just like in MySQL, it's crucial to use these statements carefully to maintain the security and integrity of your MariaDB database.

No comments:

Post a Comment

Please provide your feedback in the comments section above. Please don't forget to follow.