Grant and revoke permissions in MySQL

Source: Internet
Author: User
Tags mysql view

Grant and revoke permissions in MySQL

The simple format of commands granted to users by MySQL is as follows:
1 grant permissions on database objects to users
1. grant normal data users the right to query, insert, update, and delete all table data in the database
1 grant select on testdb.* to common_user@'%'  2 grant insert on testdb.* to common_user@'%'  3 grant update on testdb.* to common_user@'%'  4 grant delete on testdb.* to common_user@'%' 
Alternatively, replace the following with a MySQL command:
1 grant select, insert, update, delete on testdb. * to common_user @ '%'2. grant database developers the permissions to create tables, indexes, views, stored procedures, and functionsGrant permissions to create, modify, and delete MySQL Data Table structures.
1 grant create on testdb.* to developer@'192.168.0.%';  2 grant alter  on testdb.* to developer@'192.168.0.%';  3 grant drop   on testdb.* to developer@'192.168.0.%';  
Grant the MySQL foreign key operation permission:
1 grant references on testdb. * to developer @ '2017. 192.% ';
Grant MySQL temporary table operation permissions: 1 grant create temporary tables on testdb. * to developer @ '192. 192.% ';
Grant permission to operate MySQL indexes: 1 grant index on testdb. * to developer @ '2017. 192.% ';
Grant permission to operate MySQL view and view source code:
1 grant create view on testdb.* to developer@'192.168.0.%';  2 grant show   view on testdb.* to developer@'192.168.0.%';  
Grant permissions to operate MySQL stored procedures and functions:
1 grant create routine on testdb.* to developer@'192.168.0.%'; -- now, can show procedure status  2 grant alter  routine on testdb.* to developer@'192.168.0.%'; -- now, you can drop a procedure  3 grant execute        on testdb.* to developer@'192.168.0.%';  
3. grant common DBA permission to manage a MySQL database1 grant all privileges on testdb to dba @ 'localhost', where the keyword "privileges" can be omitted.
Iv. grant senior DBA permission to manage all databases in MySQL: 1 grant all on *. * to dba @ 'localhost'
V. MySQL grant permissions can be applied to multiple levels.1. grant applies to the entire MySQL Server:
1 grant select on *. * to dba @ localhost; -- dba can query tables in all databases in MySQL. 2 grant all on *. * to dba @ localhost; -- dba can manage all databases in MySQL
2. grant applies to a single database:
1 grant select on testdb. * to dba @ localhost; -- dba can query tables in testdb.
3. grant applies to a single data table:
1 grant select, insert, update, delete on testdb.orders to dba@localhost;  
When you authorize a user to multiple tables, you can execute the preceding statements multiple times. For example:
1 grant select(user_id,username) on smp.users to mo_user@'%' identified by '123345';  2 grant select on smp.mo_sms to mo_user@'%' identified by '123345';  
4. grant applies to columns in the table:
1 grant select(id, se, rank) on testdb.apache_log to dba@localhost;  
5. grant applies to stored procedures and functions:
1 grant execute on procedure testdb.pr_add to 'dba'@'localhost'  2 grant execute on function testdb.fn_add to 'dba'@'localhost'  
Vi. View MySQL user permissionsView Current user (own) permissions:
1 show grants;  
View other MySQL user permissions:
1 show grants for dba@localhost;  
7. revoke permissions granted to MySQL users.The syntax of revoke is similar to that of grant. You only need to replace the keyword "to" with "from:
1 grant  all on *.* to   dba@localhost;  2 revoke all on *.* from dba@localhost; 
VIII. Considerations for MySQL grant and revoke User Permissions1. After the grant and revoke permissions are granted, the permissions can only take effect after the user reconnects to the MySQL database. 2. If you want to grant the authorized users, you can grant these permissions to other users. You need to select "grant option".
1 grant select on testdb.* to dba@localhost with grant option;  
This feature is generally unavailable. In practice, it is best for DBAs to manage database permissions in a unified manner. In addition, there are five mysql authorization tables: user, db, host, tables_priv, and columns_priv. The authorization table has the following functions:User tableThe user table lists the users that can connect to the server and their passwords, and specifies which global (Super user) permissions they have. All permissions enabled in the user table are global permissions and apply to all databases. For example, if you have enabled the DELETE permission, the users listed here can DELETE records from any table, so you should consider it carefully before doing so.Db tableThe database table lists the databases, and the user has the permission to access them. The permission specified here applies to all tables in a database.Host tableThe host table and db table are used in combination to control the database access permissions of a specific host at a good level, which may be better than using the database separately. This table is not affected by the GRANT and REVOKE statements, so you may find that you are not using it at all.Tables_priv tableThe tables_priv table specifies table-level permissions. The specified Permission applies to all columns in a table.Columns_priv tableThe columns_priv table specifies the column-level permission. The specified Permission applies to specific columns of a table.

Reprinted Please note: http://www.cnblogs.com/fnlingnzb-learner/p/5833337.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.