mysql權限機制
mysql -h -P -u -p -e
-h 指定主機名
-P 指定mysql服務器端口
-u 指定用戶名
-p 指登錄定密碼
-e 接SQL語句
創建用戶
1.create user wing;
create user wing@‘localhost’ identified by‘12345‘;
2.grant ALL on . to ‘user‘@‘localhost‘ identified by ‘123456‘
flush privileges;
刪除用戶
drop user ‘ueer1’@‘localhost’;
delete from mysql.user
where uesr=‘user2‘ and host=‘localhost‘
修改用戶名和密碼
==root修改自己密碼
1.mysqladmin -uroot -p‘123‘ password ‘new_password ‘
2.mysql>update mysql.user set authentication_string=password(mima) where user=‘root‘ and host=‘localhost‘;
3.set password=‘new_password‘;
==root修改其他用戶密碼
1.set password for user3@‘localhost‘=‘new_password‘;
2.update mysql.user set authentication_string=password(‘new_password‘) where user=‘user3‘ and host=‘localhost‘;
set password=password(‘new_password‘);
alter user ‘wing‘ @‘localhost‘ identified by ‘new_password‘;
root賬戶沒了或者root密碼丟失:
關閉Mysql使用下面方式進入Mysql直接修改表權限
5.1/5.5版本 :
#mysqld_safe --skip-grant-tables --user=mysql &
5.6/5.7版本:
#mysqld --skip-grant-tables --user=mysql &
#mysql -uroot
mysql> UPDATE mysql.user SET authentication_string=password(‘new_password’)
WHERE user=’root’ AND host=’localhost’;
mysql> FLUSH PRIVILEGES;
======================================
密碼復雜度限制策略:
MySQL5.7默認安裝了validate_password插件,若沒有安裝,則SHOW VARIABLES LIKE ‘vali%‘則會返回空。
1、查看現有的密碼策略
mysql> SHOW VARIABLES LIKE ‘validate_password%‘;
參數解釋:
1).validate_password_dictionary_file 指定密碼驗證的文件路徑;
2).validate_password_length 密碼最小長度
3).validate_password_mixed_case_count 密碼至少要包含的小寫字母個數和大寫字母個數;
4).validate_password_number_count 密碼至少要包含的數字個數
5).validate_password_policy 密碼強度檢查等級,對應等級為:0/LOW、1/MEDIUM、2/STRONG,默認為1
0/LOW:只檢查長度;
1/MEDIUM:檢查長度、數字、大小寫、特殊字符;
2/STRONG:檢查長度、數字、大小寫、特殊字符字典文件。
6).validate_password_special_char_count密碼至少要包含的特殊字符數
2、創建用戶時報錯:
mysql> create user ‘miner‘@‘192.168.%‘ IDENTIFIED BY ‘miner123‘;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
報錯原因:密碼強度不夠。
解決方法:(該賬號為測試賬號,所以采用降低密碼策略強度)
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=4;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW VARIABLES LIKE ‘validate_password%‘;
+--------------------------------------+-------+
| Variable_name | Value |
+--------------------------------------+-------+
| validate_password_dictionary_file | |
| validate_password_length | 4 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | LOW |
| validate_password_special_char_count | 1 |
+--------------------------------------+-------+
6 rows in set (0.00 sec)
再次創建用戶,成功
3.關閉validate_password插件:
在配置文件中加入以下並重啟mysqld即可:
[mysqld]
validate_password=off
重啟mysqld後通過SHOW PLUGINS可以查到:
+-------------------+----------+-------------------+----------------------+-----+
| validate_password | DISABLED | VALIDATE PASSWORD | validate_password.so | GPL |
+-------------------+----------+-------------------+----------------------+-----+
======================================
用戶重命名:
RENAME USER old_name TO new_name;
創建賬戶:
mysql> create user tom@‘%‘ identified by ‘123‘;
%不包括127.0.0.1但是包括localhost (-h的時候適用)
遠程登陸:
#mysql -u tom -p123 -h 10.18.44.196 -P 3307
mysql權限機制