mysql grant配置授權

新建一個用戶admin1對所有的庫表完全權限,允許從任何地方訪問,密碼設爲123456
Query OK, 0 rows affected, 1 warning (0.00 sec)
語法爲

grant 權限l列表 on 庫名.表名 用戶名@“用戶地址” identified by " 密碼" [ with grant opion ];

mysql> grant all on . to admin2@"%" identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)
all 匹配所有權限
. 匹配所有庫和表
” %“ 匹配所有主機

授權用戶admin3 允許對192.168.4.0/24網段訪問

mysql> grant all on . to admin3@'192.168.4.0/24' identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

對用戶admin4在daydb4.user1僅有查詢權限 登錄密碼爲123456
mysql> grant select on daydb4.user1 to admin4@"localhost" identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.00 sec)

授權admin5 允許i本機訪問,對daydb4任何表有查詢 更改 插入 刪除 權限 密碼123456

mysql> grant select,update,delete,insert on daydb4.* to admin4@"localhost" identified by "123456" with grant option;
Query OK, 0 rows affected, 1 warning (0.01 sec)

用戶查看自己的授權

mysql> show grants;

+---------------------------------------------------------------------+
| Grants for root@localhost |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON . TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)

root 查看其他人用戶的授權
show grant for 用戶名@“客戶端地址”;

mysql> show grants for admin4@"localhost" \g;
+----------------------------------------------------------------------------------------------+
| Grants for admin4@localhost |
+----------------------------------------------------------------------------------------------+
| GRANT USAGE ON . TO 'admin4'@'localhost' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON daydb4.* TO 'admin4'@'localhost' WITH GRANT OPTION |
| GRANT SELECT ON daydb4.user1 TO 'admin4'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------+
3 rows in set (0.00 sec)
用戶鏈接後修改密碼
set password=password("新密碼");

[root@MySQL50 ~]# mysql -uadmin4 -p654321
[root@MySQL50 ~]# mysql -uadmin4 -p654321
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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>
mysql> set password=password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章