JIYIK CN >

Current Location:Home > Learning > DATABASE > MySQL >

Revoking Privileges in MySQL

Author:JIYIK Last Updated:2025/04/23 Views:

In this article, we will learn how to revoke MySQL privileges.


Revoking Privileges in MySQL

The actions that a MySQL account is allowed to perform depend on the privileges assigned to it. The context in which each type of MySQL privilege is used and its respective level of action varies.

The grant tables in the MySQL system database contain data about account privileges.

System administrators can use the GRANT statement to provide privileges and roles to MySQL user accounts, allowing those accounts to access assigned permissions on the database as needed.

GRANT privilege_name ON object_name TO user_name;

The privilege or access rights granted to the user account are specified by privilege_name. If you want to grant all privileges, separate multiple privileges with the comma operator.

The privilege level at which access is provided is determined by object_name. It includes granting access to a table; the name of the table should be the object.

The account name of the user to whom access will be provided is determined by user_name. A list of permission levels is provided below.

  1. Global
  2. Database
  3. Table
  4. Column
  5. Stored Routine
  6. Proxy

Consider the following example to help you better understand the previous idea.

> GRANT ALL ON *.* TO user_name@localhost;

Execute the above command to provide user_name@localhost access to all databases on the current server. To revoke access to user account privileges, MySQL provides REVOKEstatement.

By using the revoke statement, a system administrator can prevent a MySQL user account from using database privileges that were granted in the past.

REVOKE privilege_name ON object_name FROM user_name;

The privileges or access rights granted to the user account are specified by privilege_name. If you want to revoke them, separate multiple privileges using the comma operator.

The privilege level at which access is provided is determined by object_name. It includes granting access to a table; the name of the table should be the object.

The account name of the user whose access we want to revoke is identified by user_name. Consider the following example to help you better understand the previous idea.

> REVOKE ALL ON *.* FROM user_name@localhost;
> REVOKE ALL, GRANT OPTION FROM user_name@localhost;
> REVOKE ALL PRIVILEGES, GRANT OPTION FROM user_1 , user_2 ...

Execute the above command to revoke user_name@localhost's access rights to all databases on the current server. Execute the second command to remove all permissions granted to the user.

Use the third syntax to remove all privileges for the specified user or role. This removes all global, database, table, column, and routine privileges.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Display tables and database structure in MySQL

Publish Date:2025/04/23 Views:97 Category:MySQL

Today, we will learn about queries in MySQL that can display the table and database structure. We will use the mysqldump utility, DESCRIBE the , SHOW TABLES and SHOW CREATE TABLE the statements. We are using MySQL version 8.0.28 while writi

Select first row from MySQL table

Publish Date:2025/04/23 Views:112 Category:MySQL

Today, we will explore three scenarios and their solutions where we want to select the first row from a MySQL table. In the first scenario, we will learn to get the first row from a MySQL table where there are multiple instances of a partic

Insert timestamp into MySQL table

Publish Date:2025/04/23 Views:77 Category:MySQL

Today, we will learn how to TIMESTAMP insert date and time into a type column of a MySQL table according to the table definition. Create a MySQL table First, we will create the tables that we will use in this tutorial. Sample code: CREATE T

The difference between two tables in MySQL

Publish Date:2025/04/23 Views:102 Category:MySQL

In this article, we will learn how to find the difference between two tables in MySQL. The difference between two tables in MySQL We often need to compare two tables to find records in one table that have no matching records in the other ta

MySQL sorts data alphabetically

Publish Date:2025/04/23 Views:129 Category:MySQL

In this article, we will learn about various ways to sort data alphabetically in MySQL. Sort MySQL data alphabetically When you use the SELECT command to query data from a table, the rows in the result set are in arbitrary order. To order t

Display the current database in MySQL

Publish Date:2025/04/23 Views:199 Category:MySQL

This article focuses on the various queries that can be used to display the current database in MySQL. We will learn by using the Windows command line and MySQL Workbench. Display the current database in MySQL We can use the following query

Check if a database exists in MySQL

Publish Date:2025/04/23 Views:179 Category:MySQL

In this article, we will introduce many ways to check if a database exists in MySQL. Check if the database exists in MySQL The system schema is the schema that MySQL uses. It includes tables that contain data needed by a running MySQL serve

Get the sum of multiple columns in MySQL

Publish Date:2025/04/23 Views:125 Category:MySQL

In this article, we will learn how to sum multiple columns in MySQL. Sum multiple columns in MySQL You can use aggregate functions SUM() to calculate the total value in a collection. SUM() The function calculation does not consider NULL val

MySQL ForEach Loop

Publish Date:2025/04/23 Views:164 Category:MySQL

This article describes how to simulate a foreach loop in MySQL using INSERT, SELECT, WHERE, and JOIN in one statement. MySQL foreach loop To understand foreach loop simulation, let us create three tables with the following names and attribu

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial