您好,登錄后才能下訂單哦!
這篇文章主要講解了“如何使用MySQL角色管理”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“如何使用MySQL角色管理”吧!
1 配置 proxy
mysql> show variables like "%proxy%"; #查看當(dāng)前proxy是否開啟,OFF 表示沒(méi)有開啟 +-----------------------------------+-------+ | Variable_name | Value | +-----------------------------------+-------+ | check_proxy_users | OFF | | mysql_native_password_proxy_users | OFF | | proxy_user | | | sha256_password_proxy_users | OFF | +-----------------------------------+-------+ 4 rows in set (0.02 sec) mysql> set global check_proxy_users =on; Query OK, 0 rows affected (0.00 sec) mysql> set global mysql_native_password_proxy_users = on; Query OK, 0 rows affected (0.01 sec) mysql> exit
以上設(shè)置參數(shù),對(duì)當(dāng)前會(huì)話無(wú)效,需要退出后重新登錄,或直接設(shè)置到 my.cnf 中去;
2 創(chuàng)建角色和用戶
mysql> create user role_dba; Query OK, 0 rows affected (1.03 sec) mysql> create user 'jack'; Query OK, 0 rows affected (0.01 sec) mysql> create user 'mary'; Query OK, 0 rows affected (0.01 sec)
用戶為設(shè)置密碼,如需密碼可以使用 identified by '####' 設(shè)置;
3 權(quán)限映射
將 role_dba 的權(quán)限映射( map )到 jack 、mary
mysql> grant proxy on role_dba to jack; Query OK, 0 rows affected (0.02 sec) mysql> grant proxy on role_dba to mary; Query OK, 0 rows affected (0.01 sec)
4 給用戶賦權(quán)
給 role_dba 賦權(quán)(模擬 role 賦權(quán))
mysql> grant select on *.* to role_dba; Query OK, 0 rows affected (0.01 sec) mysql> show grants for role_dba; +---------------------------------------+ | Grants for role_dba@% | +---------------------------------------+ | GRANT SELECT ON *.* TO 'role_dba'@'%' | +---------------------------------------+ 1 row in set (0.00 sec) mysql> show grants for jack; +---------------------------------------------+ | Grants for jack@% | +---------------------------------------------+ | GRANT USAGE ON *.* TO 'jack'@'%' | | GRANT PROXY ON 'role_dba'@'%' TO 'jack'@'%' | +---------------------------------------------+ 2 rows in set (0.00 sec) mysql> show grants for mary; +---------------------------------------------+ | Grants for mary@% | +---------------------------------------------+ | GRANT USAGE ON *.* TO 'mary'@'%' | | GRANT PROXY ON 'role_dba'@'%' TO 'mary'@'%' | +---------------------------------------------+ 2 rows in set (0.00 sec)
5 查看 mysql.proxies_priv
mysql> select * from mysql.proxies_priv; +-----------+------+--------------+--------------+------------+----------------------+---------------------+ | Host | User | Proxied_host | Proxied_user | With_grant | Grantor | Timestamp | +-----------+------+--------------+--------------+------------+----------------------+---------------------+ | localhost | root | | | 1 | boot@connecting host | 0000-00-00 00:00:00 | | % | will | % | will_dba | 0 | root@localhost | 0000-00-00 00:00:00 | | % | tom | % | will_dba | 0 | root@localhost | 0000-00-00 00:00:00 | | % | jack | % | role_dba | 0 | root@localhost | 0000-00-00 00:00:00 | | % | mary | % | role_dba | 0 | root@localhost | 0000-00-00 00:00:00 | +-----------+------+--------------+--------------+------------+----------------------+---------------------+ 5 rows in set (0.01 sec)
6 驗(yàn)證
$ mysql -h 127.0.0.1 -u jack Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 249 Server version: 5.7.28-log MySQL Community Server (GPL) Copyright (c) 2000, 2019, 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> select * from test.ssd limit 1; +---+------+------+ | a | b | c | +---+------+------+ | 1 | NULL | NULL | +---+------+------+ 1 row in set (0.01 sec)
感謝各位的閱讀,以上就是“如何使用MySQL角色管理”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)如何使用MySQL角色管理這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。