MySQL adds database operation permissions to users. SQL statements

Source: Internet
Author: User
Tags mysql view

Below I will summarize some SQL statements about MySQL giving users database operation permissions, which makes it very convenient for me to authorize mysql users, these statements can only be operated by the root or super administrator.

Syntax:

The Code is as follows: Copy code

Grant all privileges on 'db _ name'. * TO 'user _ name' @ 'host' with grant option;

Example

Grant normal data users the right to query, insert, update, and delete all table data in the database.

The Code is as follows: Copy code

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:

The Code is as follows: Copy code

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


1. grant applies to the entire MySQL Server:

The Code is as follows: Copy code
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:

The Code is as follows: Copy code

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

3. grant applies to a single data table:

The Code is as follows: Copy code

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

4. grant applies to columns in the table:

The Code is as follows: Copy code

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

5. grant applies to stored procedures and functions:

The Code is as follows: Copy code

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


Grant database developers to create tables, indexes, views, stored procedures, and functions... .
Grant permissions to create, modify, and delete MySQL Data Table structures.

The Code is as follows: Copy code

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.

The Code is as follows: Copy code

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

Grant the permission to operate MySQL temporary tables.

The Code is as follows: Copy code

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

Grant the permission to operate MySQL indexes.

The Code is as follows: Copy code

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

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

The Code is as follows: Copy 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.

The Code is as follows: Copy code

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.% ';

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.