溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

mysql grant配置授權(quán)

發(fā)布時間:2020-03-04 09:22:32 來源:網(wǎng)絡(luò) 閱讀:738 作者:wx5be582d51c2c5 欄目:云計算

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

grant 權(quán)限列表 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 匹配所有權(quán)限
. 匹配所有庫和表
” %“ 匹配所有主機

授權(quán)用戶admin3 允許對192.168.4.0/24網(wǎng)段訪問

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僅有查詢權(quán)限 登錄密碼為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)

授權(quán)admin5 允許本機訪問,對daydb4任何表有查詢 更改 插入 刪除 權(quán)限 密碼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)

用戶查看自己的授權(quán)

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 查看其他人用戶的授權(quán)
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)

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI