mysql許可權機制

來源:互聯網
上載者:User

標籤:ant   length   修改表   密碼丟失   設定檔   host   spec   普通使用者   127.0.0.1   

登入和退出Mysql
mysql -h -P -u -p -e
-h 指定主機名稱
-P 指定mysql伺服器連接埠
-u 指定使用者名稱
-p 指登入定密碼
-e 接SQL語句
建立使用者
1.create user wing;
create user [email protected]‘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‘
flush privileges;
修改使用者名稱和密碼
==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 [email protected]‘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 -urootmysql> 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 [email protected]‘%‘ identified by ‘123‘;

%不包括127.0.0.1但是包括localhost (-h的時候適用)

遠程登陸:
#mysql -u tom -p123 -h 10.18.44.196 -P 3307

mysql許可權機制

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.