自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL 實戰(zhàn)筆記 第01期:MySQL 角色管理

數據庫 MySQL
角色 ( Role ) 可以用來批量管理用戶,同一個角色下的用戶,擁有相同的權限。那 MySQL 數據庫是否也有這樣的功能呢 ?答案是肯定的。MySQL 5.7.X 可以通過 mysql.proxies_priv 來模擬角色 (Role) 的功能。

[[359913]]

角色 ( Role ) 可以用來批量管理用戶,同一個角色下的用戶,擁有相同的權限。那 MySQL 數據庫是否也有這樣的功能呢 ?答案是肯定的。MySQL 5.7.X 可以通過 mysql.proxies_priv 來模擬角色 (Role) 的功能。下面讓我們來實驗一下(測試的版本 MySQL 5.7.28):

1 配置 proxy

  1. mysql> show variables like "%proxy%"; #查看當前proxy是否開啟,OFF 表示沒有開啟 
  2. +-----------------------------------+-------+ 
  3. | Variable_name                     | Value | 
  4. +-----------------------------------+-------+ 
  5. | check_proxy_users                 | OFF   | 
  6. | mysql_native_password_proxy_users | OFF   | 
  7. | proxy_user                        |       | 
  8. | sha256_password_proxy_users       | OFF   | 
  9. +-----------------------------------+-------+ 
  10. rows in set (0.02 sec) 
  11.  
  12. mysql> set global check_proxy_users =on
  13. Query OK, 0 rows affected (0.00 sec) 
  14.  
  15. mysql> set global mysql_native_password_proxy_users = on
  16. Query OK, 0 rows affected (0.01 sec) 
  17.  
  18. mysql> exit 

以上設置參數,對當前會話無效,需要退出后重新登錄,或直接設置到 my.cnf 中去;

2 創(chuàng)建角色和用戶

  1. mysql>  create user role_dba; 
  2. Query OK, 0 rows affected (1.03 sec) 
  3.  
  4. mysql> create user 'jack'
  5. Query OK, 0 rows affected (0.01 sec) 
  6.  
  7. mysql> create user 'mary'
  8. Query OK, 0 rows affected (0.01 sec) 

用戶為設置密碼,如需密碼可以使用 identified by '####' 設置;

3 權限映射

將 role_dba 的權限映射( map )到 jack 、mary

  1. mysql> grant proxy on role_dba to jack; 
  2. Query OK, 0 rows affected (0.02 sec) 
  3.  
  4. mysql> grant proxy on role_dba to mary; 
  5. Query OK, 0 rows affected (0.01 sec) 

4 給用戶賦權

給 role_dba 賦權(模擬 role 賦權)

  1. mysql> grant select on *.* to role_dba; 
  2. Query OK, 0 rows affected (0.01 sec) 
  3.  
  4. mysql> show grants for role_dba; 
  5. +---------------------------------------+ 
  6. | Grants for role_dba@%                 | 
  7. +---------------------------------------+ 
  8. GRANT SELECT ON *.* TO 'role_dba'@'%' | 
  9. +---------------------------------------+ 
  10. 1 row in set (0.00 sec) 
  11.  
  12. mysql> show grants for jack; 
  13. +---------------------------------------------+ 
  14. | Grants for jack@%                           | 
  15. +---------------------------------------------+ 
  16. GRANT USAGE ON *.* TO 'jack'@'%'            | 
  17. GRANT PROXY ON 'role_dba'@'%' TO 'jack'@'%' | 
  18. +---------------------------------------------+ 
  19. rows in set (0.00 sec) 
  20.  
  21. mysql> show grants for mary; 
  22. +---------------------------------------------+ 
  23. | Grants for mary@%                           | 
  24. +---------------------------------------------+ 
  25. GRANT USAGE ON *.* TO 'mary'@'%'            | 
  26. GRANT PROXY ON 'role_dba'@'%' TO 'mary'@'%' | 
  27. +---------------------------------------------+ 
  28. rows in set (0.00 sec) 

5 查看 mysql.proxies_priv

  1. mysql> select * from mysql.proxies_priv; 
  2. +-----------+------+--------------+--------------+------------+----------------------+---------------------+ 
  3. | Host      | User | Proxied_host | Proxied_user | With_grant | Grantor              | Timestamp           | 
  4. +-----------+------+--------------+--------------+------------+----------------------+---------------------+ 
  5. | localhost | root |              |              |          1 | boot@connecting host | 0000-00-00 00:00:00 | 
  6. | %         | will | %            | will_dba     |          0 | root@localhost       | 0000-00-00 00:00:00 | 
  7. | %         | tom  | %            | will_dba     |          0 | root@localhost       | 0000-00-00 00:00:00 | 
  8. | %         | jack | %            | role_dba     |          0 | root@localhost       | 0000-00-00 00:00:00 | 
  9. | %         | mary | %            | role_dba     |          0 | root@localhost       | 0000-00-00 00:00:00 | 
  10. +-----------+------+--------------+--------------+------------+----------------------+---------------------+ 
  11. rows in set (0.01 sec) 

6 驗證

  1. $ mysql -h 127.0.0.1 -u jack  
  2.  
  3. Welcome to the MySQL monitor. Commands end with ; or \g. 
  4.  
  5. Your MySQL connection id is 249 
  6.  
  7. Server version: 5.7.28-log MySQL Community Server (GPL) 
  8.  
  9. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. 
  10.  
  11. Oracle is a registered trademark of Oracle Corporation and/or its 
  12.  
  13. affiliates. Other names may be trademarks of their respective 
  14.  
  15. owners. 
  16.  
  17. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 
  18.  
  19. mysql> select * from test.ssd limit 1; 
  20.  
  21. +---+------+------+ 
  22.  
  23. | a | b  | c  | 
  24.  
  25. +---+------+------+ 
  26.  
  27. | 1 | NULL | NULL | 
  28.  
  29. +---+------+------+ 
  30.  
  31. 1 row in set (0.01 sec) 

mysql.proxies_priv 僅僅是對 Role 的模擬,和 Oracle 的角色還是有所不同的;官方稱呼為 Role like。

MySQL 8.0 正式增加了 role 功能,有興趣的同學可以自行了解。MySQL 5.6.X 模擬 Role 功能需要安裝插件,具體方法可參考:https://dev.mysql.com/doc/refman/5.6/en/proxy-users.htmlhttps://dev.mysql.com/doc/refman/5.6/en/pluggable-authentication.html 

責任編輯:龐桂玉 來源: 楊建榮的學習筆記
相關推薦

2020-12-24 18:00:45

MySQL元數據鎖數據庫

2018-05-03 10:33:14

數據庫MySQL 8.0角色管理

2021-04-16 10:35:14

MySQL權限管理

2009-06-16 13:09:15

Hibernate實戰(zhàn)Hibernate

2009-06-18 14:20:45

hibernate實戰(zhàn)

2017-06-30 13:00:40

倉儲信息化ERP

2011-08-16 14:14:22

MySQL數據庫初學者

2021-04-23 10:31:18

MySQLRole數據庫

2012-02-07 15:29:45

開發(fā)技術周刊

2016-07-15 09:08:12

V課堂數字化制造

2009-04-20 08:51:50

MySQL查詢優(yōu)化數據庫

2013-01-21 13:41:59

IBMdW

2017-10-09 22:33:56

SQL等值分組有序分組

2015-11-11 14:54:35

網絡·安全技術周刊

2020-02-14 16:20:19

大咖來了IT管理者

2017-10-18 22:34:33

SQL等值分組有序分組

2017-09-05 22:34:24

遍歷SQL運算

2020-06-22 10:19:58

技術資訊

2022-05-17 11:06:44

數據庫MySQL系統(tǒng)
點贊
收藏

51CTO技術棧公眾號