2019年3月12日 星期二

【MYSQL】 權限說明及創建

授予權限指令:
grant 權限(參考表1) on (權限範圍如*.*或dbname.*) to '用戶'@'IP' identified by '密碼';
此指令在給予帳號時就會自動創建帳號 ,等同於先create 再 grant意思相同
mysql> grant select,update on *.* to 'root'@'localhost' identified by '1234';





給予 rosalie 在 test 資料庫所有的權限(privileges可加可不加,效果相同)
mysql> grant all on test.* to 'rosalie'@'localhost' identified by '1234';
mysql> grant all privileges on test.* to 'rosalie'@’localhost' identified by '1234'; 
查看MYSQL所有使用者帳號
mysql> select user,host from mysql.user;

#5.7版後查詢
mysql> select user,host,authentication_string from mysql.user;
查看MYSQL某使用者rosalie的權限
mysql> show grants for 'rosalie'@'localhost';
+----------------------------------------------------------------------------------------------------+
| Grants for rosalie@localhost                                                                           |
+----------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'rosalie'@'localhost' WITH GRANT OPTION                  |
| GRANT ALL PRIVILEGES ON `test`.* TO 'rosalie'@'localhost'                      || GRANT SELECT, INSERT, UPDATE, DELETE ON `birdwatchers`.* TO 'rosalie'@'localhost'    |
+----------------------------------------------------------------------------------------------------+
3 rows in set (0.01 sec)
移除 rosalie 在 test 資料庫讀的權限(單一權限移除)

mysql> revoke select on test.* from 'rosalie'@'localhost';
移除 rosalie 在 所有資料庫的所有權限(所有權限移除)
mysql> revoke all privileges on *.* from 'rosalie'@'localhost';
移除 rosalie 在 test 資料庫的 create,index,event 權限(多個權限移除)
mysql> revoke create,index,event on test.* from 'rosalie'@'192.1.1.1';
移除rosalie在本機的使用者帳號(移除使用者帳號)
mysql> drop user 'rosalie'@'localhost';
權限套用更新
mysql> flush privileges;
忘記密碼 ,更改原密碼變更密碼
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('7890');
5.7版密碼有較嚴格的限制,若出現錯誤訊息 ,可用以下方式解決
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements。
mysql> SHOW VARIABLES LIKE 'validate_password%';
mysql>set global validate_password_policy=0  

設好再改回 此參數指


mysql>set global validate_password_policy=1
LOW (=0):策略僅測試密碼長度。密碼長度必須至少為8個字符。
MEDIUM(=1) :策略添加了密碼必須至少包含1個數字字符,1個小寫字符,1個大寫字符和1個特殊(非字母數字)字符的條件。
STRONG(=2) :策略添加了長度為4或更長的密碼子字符串不能匹配字典文件中的字詞(如果已經指定)的條件。

5.7版再創建帳號時,若忘記加入密碼identified by的話,創建會出現,
將無法創建
ERROR 1133 (42000): Can’t find any matching row in the user table
5.6版 查詢帳號,IP,密碼
select user, host, password from mysql.user;
5.6版 若grant alter on *.* to 'rooty'@'localhost';
沒有下identified by仍可創建新帳號,但使用者無密碼就可登入

沒有留言:

張貼留言

【MYSQL】MYSQL的SYS表說明(版本8.0)

mysql> use sys Reading table information for completion of table and column names You can turn off this feature to get a quicker s...