Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the MySQL authorization command grant

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

How to use the MySQL authorization command grant? Many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can gain something.

This article is an example, running on MySQL version 5.0 and above.

The simple format of the command granted by MySQL to the user can be summarized as follows:

Grant permissions on database object to user

Recommended for related study: mysql video tutorial

Grant ordinary data users have the right to query, insert, update and delete all table data 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, replace it with a MySQL command:

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

Second, grant database developers, create tables, indexes, views, stored procedures, functions. Wait for permission.

Grant creates, modifies, and deletes MySQL data table structure permissions.

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 manipulates MySQL foreign key permissions.

Grant references on testdb.* to developer@'192.168.0.%'

Grant manipulates MySQL temporary table permissions.

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

Grant manipulates MySQL index permissions.

Grant index on testdb.* to developer@'192.168.0.%'

Grant manipulates MySQL view and view view source code permissions.

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

Grant manipulates MySQL stored procedures and function permissions.

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

Third, the permission of grant ordinary DBA to manage a MySQL database.

Grant all privileges on testdb to dba@'localhost'

The keyword "privileges" can be omitted.

4. Grant Advanced DBA manages the permissions of all databases in MySQL.

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

Fifth, MySQL grant permissions, which can be used at multiple levels.

1. Grant acts on 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 acts on 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 to a user, the above statements 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. View MySQL user permissions

View current user (own) permissions:

Show grants

View additional MySQL user rights:

Show grants for dba@localhost

Revoke the permissions that have been granted to MySQL users.

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

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

VIII. Considerations for user rights of MySQL grant and revoke

1. After the grant, revoke user permission, the user will not take effect until the user reconnects to the MySQL database.

two。 If you want authorized users, you can also 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 needed. In practice, database permissions are best managed by DBA.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report