标签:
| 表名 | user | db | host |
| 用户列 | User | Host | Host |
| Password | Db | Db | |
| 权限列 | Select_priv | User | Select_priv |
| Insert_priv | Select_priv | Insert_priv | |
| Update_priv | Insert_priv | Update_priv | |
| Delete_priv | Update_priv | Delete_priv | |
| Create_priv | Delete_priv | Create_priv | |
| Drop_priv | Create_priv | Drop_priv | |
| Reload_priv | Drop_priv | Grant_priv | |
| Shutdown_priv | Grant_priv | References_priv | |
| Process_priv | References_priv | Index_priv | |
| File_priv | Index_priv | Alter_priv | |
| Grant_priv | Alter_priv | Create_tmp_table_priv | |
| References_priv | Create_tmp_table_priv | Lock_tables_priv | |
| Index_priv | Lock_tables_priv | Create_view_priv | |
| Alter_priv | Create_view_priv | Show_view_priv | |
| Show_db_priv | Show_view_priv | Create_routine_priv | |
| Super_priv | Create_routine_priv | Alter_routine_priv | |
| Create_tmp_table_priv | Alter_routine_priv | Execute_priv | |
| Lock_tables_priv | Execute_priv | Trigger_priv | |
| Execute_priv | Event_priv | ||
| Repl_slave_priv | Trigger_priv | ||
| Repl_client_priv | |||
| Create_view_priv | |||
| Show_view_priv | |||
| Create_routine_priv | |||
| Alter_routine_priv | |||
| Create_user_priv | |||
| Event_priv | |||
| Trigger_priv | |||
| Create_tablespace_priv | |||
| 安全列 | ssl_type | ||
| ssl_cipher | |||
| x509_issuer | |||
| x509_subject | |||
| max_questions | |||
| max_updates | |||
| max_connections | |||
| max_user_connections |
mysql> grant select on *.* to cqh@localhost;
Query OK, 0 rows affected (0.05 sec)
mysql> select * from user where user=‘cqh‘ and host=‘localhost‘ \G
*************************** 1. row ***************************
Host: localhost
User: cqh
Password:
Select_priv: Y
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
...
mysql> select * from db where user=‘cqh‘; Empty set (0.00 sec)
mysql> revoke select on *.* from cqh@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select on test.* to cqh@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user where user=‘cqh‘ and host=‘localhost‘ \G
*************************** 1. row ***************************
Host: localhost
User: cqh
Password:
Select_priv: N
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Show_db_priv: N
Super_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Execute_priv: N
Repl_slave_priv: N
Repl_client_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Create_user_priv: N
Event_priv: N
Trigger_priv: N
Create_tablespace_priv: N
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin:
authentication_string: NULL
1 row in set (0.00 sec)
mysql> select * from db where user=‘cqh‘\G
*************************** 1. row ***************************
Host: localhost
Db: test
User: cqh
Select_priv: Y
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Execute_priv: N
Event_priv: N
Trigger_priv: N
1 row in set (0.00 sec)
GRANT
priv_type [(column_list)]
[, priv_type [(column_list)]] ...
ON [object_type] priv_level
TO user_specification [, user_specification] ...
[REQUIRE {NONE | ssl_option [[AND] ssl_option] ...}]
[WITH with_option ...]
GRANT PROXY ON user_specification
TO user_specification [, user_specification] ...
[WITH GRANT OPTION]
object_type:
TABLE
| FUNCTION
| PROCEDURE
mysql> grant all privileges on *.* to cqh@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user where user=‘cqh‘ and host=‘localhost‘ \G
*************************** 1. row ***************************
Host: localhost
User: cqh
Password:
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: N
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin:
authentication_string: NULL
1 row in set (0.00 sec)
mysql> grant all privileges on *.* to cqh@localhost with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user where user=‘cqh‘ and host=‘localhost‘ \G
*************************** 1. row ***************************
Host: localhost
User: cqh
Password:
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin:
authentication_string: NULL
1 row in set (0.00 sec)
mysql> grant all privileges on *.* to cqh@localhost identified by ‘123‘ with grant option; Query OK, 0 rows affected (0.00 sec)
mysql> select * from user where user=‘cqh‘ and host=‘localhost‘ \G
*************************** 1. row ***************************
Host: localhost
User: cqh
Password: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: Y
Drop_priv: Y
Reload_priv: Y
Shutdown_priv: Y
Process_priv: Y
File_priv: Y
Grant_priv: Y
References_priv: Y
Index_priv: Y
Alter_priv: Y
Show_db_priv: Y
Super_priv: Y
Create_tmp_table_priv: Y
Lock_tables_priv: Y
Execute_priv: Y
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: Y
Show_view_priv: Y
Create_routine_priv: Y
Alter_routine_priv: Y
Create_user_priv: Y
Event_priv: Y
Trigger_priv: Y
Create_tablespace_priv: Y
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin:
authentication_string: NULL
1 row in set (0.00 sec)
mysql> grant select,insert,update,delete on test.* to ‘chenqionghe‘@‘%‘ identified by ‘123‘;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from user where user=‘chenqionghe‘ and host=‘%‘ \G
*************************** 1. row ***************************
Host: %
User: chenqionghe
Password: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257
Select_priv: N
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Show_db_priv: N
Super_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Execute_priv: N
Repl_slave_priv: N
Repl_client_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Create_user_priv: N
Event_priv: N
Trigger_priv: N
Create_tablespace_priv: N
ssl_type:
ssl_cipher:
x509_issuer:
x509_subject:
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin:
authentication_string: NULL
1 row in set (0.00 sec)
mysql> select * from db where user=‘chenqionghe‘ and host=‘%‘ \G
*************************** 1. row ***************************
Host: %
Db: test
User: chenqionghe
Select_priv: Y
Insert_priv: Y
Update_priv: Y
Delete_priv: Y
Create_priv: N
Drop_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Execute_priv: N
Event_priv: N
Trigger_priv: N
1 row in set (0.00 sec)
| Host值 | User值 | 被条目匹配的连接 |
| cqh.loc.gov | cqh | cqh,从cqh.loc.gov连接 |
| cqh.loc.gov | 任何用户,从cqh.loc.gov连接 | |
| % | cqh | cqh,从任何主机连接 |
| % | 任何用户,从任何主机连接 | |
| %.loc.gov | cqh | cqh,从在loc.gov域的任何主机连接 |
| x.y.% | cqh | cqh,从x.y.net、x.y.com、x.y.edu等连接 |
| 114.115.166.177 | cqh | cqh,从有114.115.166.177IP地址的主机连接 |
| 114.115.166.% | cqh | cqh,从144.155.166C类子网的任何主机连接 |
mysql> grant super,process,file on *.* to ‘cqh2‘@‘%‘; Query OK, 0 rows affected (0.00 sec)
mysql> grant super,process,file on test.* to ‘cqh2‘@‘%‘; ERROR 1221 (HY000): Incorrect usage of DB GRANT and GLOBAL PRIVILEGES
mysql> grant usage on *.* to ‘cqh3‘@‘localhost‘; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye [root@iZ28dr6w0qvZ ~]# mysql -ucqh3 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1640 Server version: 5.5.37-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | +--------------------+ 1 row in set (0.00 sec)
mysql> grant select,insert,update,delete on test.* to ‘chenqionghe‘@‘%‘ identified by ‘123‘;
[root@iZ28dr6w0qvZ ~]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1560 Server version: 5.5.37-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> use mysql; Database changed mysql> insert into db (host,db,user,select_priv,insert_priv,update_priv,delete_priv) values (‘%‘,‘test‘,‘chenqionghe‘,‘Y‘,‘Y‘,‘Y‘,‘Y‘); Query OK, 1 row affected (0.00 sec) mysql> flush privileges; mysql> exit; Bye [root@iZ28dr6w0qvZ ~]# mysql -ucqh3 ERROR 1045 (28000): Access denied for user ‘cqh3‘@‘localhost‘ (using password: NO) [root@iZ28dr6w0qvZ ~]# mysql -ucqh3 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1643 Server version: 5.5.37-log MySQL Community Server (GPL) Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | test | +--------------------+ 2 rows in set (0.00 sec)
show grants for user@host;
mysql> show grants for cqh@localhost; +---------------------------------------------------------------------------------------------------------------------------------------+ | Grants for cqh@localhost | +---------------------------------------------------------------------------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO ‘cqh‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘*23AE809DDACAF96AF0FD78ED04B6A265E05AA257‘ WITH GRANT OPTION | | GRANT SELECT ON `test`.* TO ‘cqh‘@‘localhost‘ | +---------------------------------------------------------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
mysql> show grants for chenqionghe; +------------------------------------------------------------------------------------------------------------+ | Grants for chenqionghe@% | +------------------------------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO ‘chenqionghe‘@‘%‘ IDENTIFIED BY PASSWORD ‘*23AE809DDACAF96AF0FD78ED04B6A265E05AA257‘ | +------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> select * from SCHEMA_PRIVILEGES where grantee="‘cqh‘@‘localhost‘"; +-------------------+---------------+--------------+----------------+--------------+ | GRANTEE | TABLE_CATALOG | TABLE_SCHEMA | PRIVILEGE_TYPE | IS_GRANTABLE | +-------------------+---------------+--------------+----------------+--------------+ | ‘cqh‘@‘localhost‘ | def | test | SELECT | NO | +-------------------+---------------+--------------+----------------+--------------+ 1 row in set (0.00 sec)
mysql> show grants for cqh3@localhost; +------------------------------------------+ | Grants for cqh3@localhost | +------------------------------------------+ | GRANT USAGE ON *.* TO ‘cqh3‘@‘localhost‘ | +------------------------------------------+ 1 row in set (0.00 sec)
mysql> grant select on *.* to ‘cqh3‘@‘localhost‘; Query OK, 0 rows affected (0.00 sec) mysql> show grants for cqh3@localhost; +-------------------------------------------+ | Grants for cqh3@localhost | +-------------------------------------------+ | GRANT SELECT ON *.* TO ‘cqh3‘@‘localhost‘ | +-------------------------------------------+ 1 row in set (0.00 sec)
mysql> show grants for cqh3@localhost; +-------------------------------------------+ | Grants for cqh3@localhost | +-------------------------------------------+ | GRANT SELECT ON *.* TO ‘cqh3‘@‘localhost‘ | +-------------------------------------------+ 1 row in set (0.00 sec) mysql> grant select,insert on *.* to ‘cqh3‘@‘localhost‘; Query OK, 0 rows affected (0.00 sec) mysql> show grants for cqh3@localhost; +---------------------------------------------------+ | Grants for cqh3@localhost | +---------------------------------------------------+ | GRANT SELECT, INSERT ON *.* TO ‘cqh3‘@‘localhost‘ | +---------------------------------------------------+ 1 row in set (0.00 sec)
REVOKE
priv_type [(column_list)]
[, priv_type [(column_list)]] ...
ON [object_type] priv_level
FROM user [, user] ...
REVOKE ALL PRIVILEGES, GRANT OPTION
FROM user [, user] ...
REVOKE PROXY ON user
FROM user [, user] ...
mysql> revoke select,insert on *.* from cqh3@localhost; Query OK, 0 rows affected (0.00 sec) mysql> show grants for cqh3@localhost; +------------------------------------------+ | Grants for cqh3@localhost | +------------------------------------------+ | GRANT USAGE ON *.* TO ‘cqh3‘@‘localhost‘ | +------------------------------------------+ 1 row in set (0.00 sec)
mysql> show grants for cqh3@localhost; +------------------------------------------+ | Grants for cqh3@localhost | +------------------------------------------+ | GRANT USAGE ON *.* TO ‘cqh3‘@‘localhost‘ | +------------------------------------------+ 1 row in set (0.00 sec) mysql> revoke usage on *.* from cqh@localhost; Query OK, 0 rows affected (0.00 sec) mysql> show grants for cqh3@localhost; +------------------------------------------+ | Grants for cqh3@localhost | +------------------------------------------+ | GRANT USAGE ON *.* TO ‘cqh3‘@‘localhost‘ | +------------------------------------------+ 1 row in set (0.00 sec)
shell> mysqladmin -u user_name -h host_name password "newpwd"
SET PASSWORD FOR ‘chenqionghe‘@‘%‘ = PASSWORD(‘cqh123‘);
SET PASSWORD = PASSWORD(‘cqh123‘);
GRANT USAGE ON *.* TO ‘chenqionghe‘@‘%‘ IDENTIFIED BY ‘cqh123‘;
mysql> INSERT INTO user (Host,User,Password) VALUES(‘%‘,‘chenqionghe‘,PASSWORD(‘333333‘)); mysql> FLUSH PRIVILEGES; mysql> UPDATE user SET Password = PASSWORD(‘333333‘) WHERE Host=‘%‘ AND User=‘chenqionghe‘; mysql> FLUSH PRIVILEGES;
DROP USER user [, user] ...
mysql> show grants for cqh3@localhost; +------------------------------------------+ | Grants for cqh3@localhost | +------------------------------------------+ | GRANT USAGE ON *.* TO ‘cqh3‘@‘localhost‘ | +------------------------------------------+ 1 row in set (0.00 sec) mysql> drop user cqh3@localhost; Query OK, 0 rows affected (0.00 sec) mysql> show grants for cqh3@localhost; ERROR 1141 (42000): There is no such grant defined for user ‘cqh3‘ on host ‘localhost‘
标签:
原文地址:http://www.cnblogs.com/chenqionghe/p/4871355.html