How to use the MySQL authorization command grant

How to use the MySQL authorization command grant

The examples in this article run on MySQL 5.0 and above.

The simple format of the MySQL command for granting user permissions can be summarized as follows:

Grant permissions on database objects to users

1. Grant ordinary data users the rights to query, insert, update, and delete data in all tables in the database.

grant select on testdb.* to common_user@'%'
grant insert on testdb.* to common_user@'%'
grant update on testdb.* to common_user@'%'
grant delete on testdb.* to common_user@'%'

Or, use a MySQL command instead:

grant select, insert, update, delete on testdb.* to common_user@'%'

2. Grant database developers to create tables, indexes, views, stored procedures, and functions. . . And other permissions.

Grant permissions to create, modify, and delete MySQL table structures.

grant create on testdb.* to developer@'192.168.0.%';
grant alter on testdb.* to developer@'192.168.0.%';
grant drop on testdb.* to developer@'192.168.0.%';

Grant permissions to operate MySQL foreign keys.

grant references on testdb.* to developer@'192.168.0.%';

Grant permissions to operate MySQL temporary tables.

grant create temporary tables on testdb.* to developer@'192.168.0.%';

Grant permissions to operate MySQL indexes.

grant index on testdb.* to developer@'192.168.0.%';

Grant permissions to operate MySQL views and view view source code.

grant create view on testdb.* to developer@'192.168.0.%';
grant show view on testdb.* to developer@'192.168.0.%';

Grant permissions to operate MySQL stored procedures and functions.

grant create routine on testdb.* to developer@'192.168.0.%'; -- now, you can show procedure status
grant alter routine on testdb.* to developer@'192.168.0.%'; -- now, you can drop a procedure
grant execute on testdb.* to developer@'192.168.0.%';

3. Grant an ordinary DBA the authority to manage a MySQL database.

grant all privileges on testdb to dba@'localhost'

The keyword "privileges" can be omitted.

4. Grant senior DBA permissions to manage all databases in MySQL.

grant all on *.* to dba@'localhost'

5. MySQL grant permissions can be applied at multiple levels.

1. Grant applies to the entire MySQL server:

grant select on *.* to dba@localhost; -- dba can query tables in all databases in MySQL.
grant all on *.* to dba@localhost; -- dba can manage all databases in MySQL

2. Grant is applied to a single database:

grant select on testdb.* to dba@localhost; -- dba can query tables in testdb.

3. Grant acts on a single data table:

grant select, insert, update, delete on testdb.orders to dba@localhost;

Here, when authorizing multiple tables for a user, the above statement can be executed multiple times. For example:

grant select(user_id,username) on smp.users to mo_user@'%' identified by '123345';
grant select on smp.mo_sms to mo_user@'%' identified by '123345';

4. Grant acts on the columns in the table:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. Grant acts on stored procedures and functions:

grant execute on procedure testdb.pr_add to 'dba'@'localhost'
grant execute on function testdb.fn_add to 'dba'@'localhost'

6. Check MySQL user permissions

View the current user's (your own) permissions:

show grants;

View other MySQL user permissions:

show grants for dba@localhost;

7. Revoke the permissions that have been granted to the MySQL user.

The syntax of revoke is similar to grant, except that the keyword "to" is replaced with "from":

grant all on *.* to dba@localhost;
revoke all on *.* from dba@localhost;

8. Notes on granting and revokeing user permissions in MySQL

1. After granting or revokeing user permissions, the permissions will take effect only when the user reconnects to the MySQL database.

2. If you want the authorized user to grant these permissions to other users, you need the option "grant option"

grant select on testdb.* to dba@localhost with grant option;

This feature is generally not used. In practice, database permissions are best managed centrally by the DBA.

The above is the details of how to use the authorization command grant in MySQL. For more information about the MySQL authorization command grant, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Mysql permission management grant command to make notes
  • Detailed explanation of MySQL Grant command
  • Summary of how to use the MySQL authorization command grant

<<:  Detailed explanation of the use of stat function and stat command in Linux

>>:  JavaScript to implement the most complete code analysis of a simple shopping cart (ES6 object-oriented)

Recommend

A simple example of how to implement fuzzy query in Vue

Preface The so-called fuzzy query is to provide q...

Implementation of TypeScript in React project

Table of contents 1. Introduction 2. Usage Statel...

Solution to Nginx session loss problem

In the path of using nginx as a reverse proxy tom...

...

A friendly alternative to find in Linux (fd command)

The fd command provides a simple and straightforw...

How to upload projects to Code Cloud in Linux system

Create a new project test1 on Code Cloud Enter th...

Detailed explanation of basic operation commands for Linux network settings

Table of contents View network configuration View...

CSS scroll bar style modification code

CSS scroll bar style modification code .scroll::-...

10 reasons why Linux is becoming more and more popular

Linux has been loved by more and more users. Why ...

VMware15.5 installation Ubuntu20.04 graphic tutorial

1. Preparation before installation 1. Download th...

Detailed explanation of Linux file operation knowledge points

Related system calls for file operations create i...

Example of integrating Kafka with Nginx

background nginx-kafka-module is a plug-in for ng...

14 techniques for high-performance websites

Original : http://developer.yahoo.com/performance...