[MySQL]-MySQL Grant command _ MySQL

Source: Internet
Author: User
Tags mysql view
[MySQL]-MySQL Grant command bitsCN.com

[MySQL]-MySQL Grant Command

This example runs on MySQL 5.0 and later.

The simple format of commands granted to users by MySQL is as follows:

Grant permission on database objects to users

1. grant normal data users 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 @ '%'

Alternatively, replace the following with a MySQL command:

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

2. grant database developers to create tables, indexes, views, stored procedures, and functions... .

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

Grant create on testdb. * to developer @ '192. 192.% ';

Grant alter on testdb. * to developer @ '192. 192.% ';

Grant drop on testdb. * to developer @ '192. 192.% ';

Grant the MySQL foreign key operation permission.

Grant references on testdb. * to developer @ '192. 192.% ';

Grant the permission to operate MySQL temporary tables.

Grant create temporary tables on testdb. * to developer @ '2017. 192.% ';

Grant the permission to operate MySQL indexes.

Grant index on testdb. * to developer @ '192. 192.% ';

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

Grant create view on testdb. * to developer @ '192. 192.% ';

Grant show view on testdb. * to developer @ '192. 192.% ';

Grant permissions to operate MySQL stored procedures and functions.

Grant create routine on testdb. * to developer @ '192. 192.% '; -- now, can show procedure status

Grant alter routine on testdb. * to developer @ '192. 192.% '; -- now, you can drop a procedure

Grant execute on testdb. * to developer @ '192. 192.% ';

3. grant common DBA permission to manage a MySQL database.

Grant all privileges on testdb to dba @ 'localhost'

The keyword "privileges" can be omitted.

4. grant Senior DBA permission to manage all databases in MySQL.

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

5. MySQL grant permissions can be applied to 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 applies to a single database:

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

3. grant applies to a single data table:

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:

Grant select (user_id, username) on smp. users to mo_user @ '% 'identified by '123 ';

Grant select on smp.mo _ sms to mo_user @ '%' identified by '123 ';

4. grant applies to columns in the table:

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

5. grant applies to stored procedures and functions:

Grant execute on procedure testdb. pr_add to 'dba '@ 'localhost'

Grant execute on function testdb. fn_add to 'dba '@ 'localhost'

VI. View MySQL User permissions

View current user (own) permissions:

Show grants;

View other MySQL User permissions:

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:

Grant all on *. * to dba @ localhost;

Revoke all on *. * from dba @ localhost;

VIII. considerations for MySQL grant and revoke user permissions

1. 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".

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 the case of the SELECT command denied to user 'username' @ 'hostname 'for table 'table name' error, you need to authorize the table name following it, that is, you need to authorize the core database.

BitsCN.com

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.