Grant mysqlgrant permissions to bitsCN.com
Mysql grant permission allocation
Change password
1. modify data in the database
Mysql-u root-p Press enter
Enter password
Mysql> user mysql
Mysql> select user, password from user; # View password
# It can be seen that the password is 41 bits. it is not recommended to directly modify this table, but it can be modified using the function compute password.
Mysql> select PASSWORD ('ABC ');
# Be careful when changing the password to the calculated value based on specific conditions.
[C]
Mysql-u root-p Press enter
Enter password
Mysql> user mysql
Mysql> select user, password from user; # View password
# It can be seen that the password is 41 bits. it is not recommended to directly modify this table, but it can be modified using the function compute password.
Mysql> select PASSWORD ('ABC ');
# Be careful when changing the password to the calculated value based on specific conditions.
2. change the root password to yourpassword in the command line.
Mysqladmin-u root-p PASSWORD yourpassword press enter
Enter the original password
[C]
Mysqladmin-u root-p PASSWORD yourpassword press enter
Enter the original password
3. use set password. for example, change the root PASSWORD to yourpasswd:
Mysql> set password for root @ localhost = PASSWORD ('yourpasswd ');
[C]
Mysql> set password for root @ localhost = PASSWORD ('yourpasswd ');
4. Use GRANT... IDENTIFIED. for example, change the root password to youpassword:
Mysql> grant usage on *. * TO root @ localhost identified by 'yourpassword ';
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 @ '2017. 192.% ';
Grant alter on testdb. * to developer @ '192. 192.% ';
Grant drop on testdb. * to developer @ '192. 192.% ';
MySQLgrant is used to operate MySQL foreign keys.
Grant references on testdb. * to developer @ '192. 192.% ';
Grant the permission to operate MySQL temporary tables.
Grant create temporary tables on testdb. *
Grant the permission to operate MySQL indexes.
Grant index on testdb. *
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.
MySQLgrant all privileges on testdb
The keyword "privileges" can be omitted.
Grant execute on procedure testdb. pr_add to 'dba '@ 'localhost'
Grant execute on function testdb. fn_add to 'dba '@ 'localhost'
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
4. grant applies to columns in the table:
Grant select (id, se, rank) on testdb. apache_log
5. MySQL 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 authorize the user, you can also grant these permissions to other users. you need to select "grant option".
Grant select on testdb. * to dba @ localhost with grant option;
BitsCN.com