[MySQL]-MySQL Grant command

Source: Internet
Author: User
Tags mysql view

[MySQL]-MySQL Grant command example in this article, run in MySQL 5.0 and later versions. The simple format of commands granted by MySQL to users can be summarized as: grant permissions on database objects to users 1. grant common 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 @ '%' or use a MySQL command to replace: grant select, insert, update, delete on testdb. * to common_user @ '%' 2. grant the database developer 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 @ '2017. 168.0.% '; grant alter on testdb. * to developer @ '2017. 168.0.% '; grant drop on testdb. * to developer @ '2017. 168.0.% '; grant the permission to operate the MySQL foreign key. Grant references on testdb. * to developer @ '192. 192.% '; grant the temporary table permission for MySQL. Grant create temporary tables on testdb. * to developer @ '192. 192.% '; grant permission to operate MySQL indexes. Grant index on testdb. * to developer @ '192. 192.% '; grant permission to operate MySQL view and view source code. Grant create view on testdb. * to developer @ '2017. 168.0.% '; grant show view on testdb. * to developer @ '2017. 168.0.% '; grant permissions to operate MySQL stored procedures and functions. Grant create routine on testdb. * to developer @ '2017. 168.0.% '; -- now, can show procedure statusgrant alter routine on testdb. * to developer @ '2017. 168.0.% '; -- now, you can drop a proceduregrant execute on testdb. * to developer @ '2017. 168.0.% '; 3. grant common DBA permission to manage a MySQL database. Grant all privileges on testdb to dba @ 'localhost', where the keyword "privileges" can be omitted. 4. grant senior DBA permission to manage all databases in MySQL. Grant all on *. * to dba @ 'localhost' v. 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 works on 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; the preceding statements can be executed multiple times when a user is authorized to multiple tables. Example: grant select (user_id, username) on smp. users to mo_user @ '%' identified by '000000'; grant select on smp.mo _ sms to mo_user @ '%' identified by '000000'; 4. grant is applied to columns in the Table: grant select (id, se, rank) on testdb. apache_log to dba @ localhost; 5. grant is used in 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 and view current user (own) Permissions Limit: show grants; view other MySQL user permissions: show grants for dba @ localhost; 7. revoke the permissions granted to MySQL users. The revoke syntax 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; 8. Considerations for MySQL grant and revoke User Permissions 1. grant and revoke permissions can only take effect after the user reconnects to the MySQL database. 2. if you want the authorized user to 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.

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.