• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Understanding the REVOKE statement in MySQL

by admin

The REVOKE command is used to rescind privileges previously granted to a user. Its syntax is:

REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
       ON {tbl_name | * | *.* | db_name.*}
       FROM user_name [, user_name ...]

As is the case with the GRANT command, perhaps the best way to really understand how it operates is to experiment with several examples. Assume that the administrator wants to repeal the DELETE privilege from the user widgetAdmin. This is accomplished using the following command:

mysql>REVOKE DELETE ON widgets.*
    ->FROM widgetAdmin@localhost;

One point to keep in mind is that while REVOKE can remove all privileges (including connection privileges) from a user, it does not explicitly remove that user from the privilege tables. To illustrate this, consider the following command:

mysql>REVOKE ALL PRIVILEGES ON widgets.*
    ->FROM widgetAdmin@localhost;

While this would result in all privileges being revoked from the user widgetAdmin, it would not delete the relevant rows from the privilege tables! If completely removing the user from the database is the intention, the rows would have to be removed using the delete command, as follows:

mysql>DELETE FROM user WHERE user = 'widgetAdmin';
Query OK, 1 row affected (0.00 sec)
mysql>flush privileges;

This will effectively deny that user from connecting to the MySQL server. Note that rows from the user table will have to be explicitly removed using DELETE should the administrator wish to entirely remove the user from the privilege tables.

Filed Under: mysql

Some more articles you might also be interested in …

  1. How to Restore a Specific Database or Table (MySQL)
  2. MySQL Grants – Setting User Permissions On Different Tables
  3. Backup and Restore Of Group Replication Node ( MySQL 8.0 )
  4. How to Generate Unique IDs For MySQL Cluster Backups
  5. How To Install MySQL RPM packages in a different location to allow multiple versions (versions < 5.6.10)
  6. What is the meaning of the TRX_TABLES_LOCKED column in the information_schema.INNODB_TRX MySQL table
  7. How to List Users and Privileges in MySQL
  8. What are the various types of locking used in the MySQL Server
  9. What is an Arbitrator in MySQL Cluster
  10. How To Create a Local Yum Repository for MySQL Enterprise Packages

You May Also Like

Primary Sidebar

Recent Posts

  • qtchooser Command Examples in Linux
  • qtchooser: command not found
  • qsub Command Examples in Linux
  • qsub: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright