mysql8出现1045报错+常用的加密plugin汇总
一些準備工作
/etc/mysql/mysql.conf.d/mysqld.cnf
的[mysqld]下面加入skip-grant-tables
service mysql restart
然后輸入mysql就可以登錄客戶端
?
操作列表
操作 | 命令 | 使用備注(必須遵守,否則會碰到相關error) |
| 查詢使用的plugin | use mysql; select user,plugin from user where user='appleyuchi'; | 無 |
| 更換plugin | update user set plugin='mysql_native_password' where user='root'; | 無 |
| 查詢授權的/host/user/authentication_string | select host,user,authentication_string from mysql.user; | 無 |
| 刪除某個用戶 | drop user appleyuchi@'%' | 這里的%是上面一句命令中得到的host,也可能是其他域名或者IP |
| 查看某個用戶被授予的權限[3] | select * from mysql.user where user='appleyuchi'\G; | ? |
| 設置密碼 | ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'appleyuchi'; | 如果運行不順利參考[2]解決 |
| 新建用戶 | flush privileges; create user root@localhost identified by 'appleyuchi'; CREATE USER ?'root'@'%' IDENTIFIED BY ?'root'; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION; flush privileges; | 由于是skip-grant-tables模式, 所以有時候需要先執行flush privileges 才能繼續往下執行其他命令, 所以左側的flush privileges;執行了兩次. |
| 授予權限 | GRANT ALL PRIVILEGES ON *.* TO 'appleyuchi'@'%' WITH GRANT OPTION; | ? |
| 查看當前用戶所擁有的權限 | SHOW GRANTS FOR 'appleyuchi'@'%'; ? select host,user,Grant_priv,Super_priv from mysql.user; | ? |
| 刷新權限 | flush privileges; | ? |
| 更換密碼[5] | ALTER USER appleyuchi IDENTIFIED WITH mysql_native_password BY 'appleyuchi'; | ? |
GRANT OPTION指的是把自己的權限賦予其他用戶的能力.
all權限≠擁有grant option權限
#####################################################################################################################################
加密用的plugin
| plugin名字 | 備注 |
| auth_socket | 無密碼登錄 |
| caching_sha2_password | [1]中說不支持客戶端使用 |
| mysql_native_password | 推薦使用 |
#####################################################################################################################################
總結
根據上面的2張表格,
你除了要檢查plugin是不是mysql_native_password以外,
還要查看權限,
還要查看是否具有grant option.
缺一不可.
#####################################################################################################################################
錯誤示范
update mysql.user set authentication_string = "appleyuchi" ?where user = "appleyuchi" ;
注意上面的這個絕對是錯誤的,因為不可能使用明文保存密碼
select host,user,authentication_string from mysql.user;
得到結果如下:
?
Reference:
[1]mysql錯誤:mysql_native_password
[2]mysql8碰到ERROR 1396 (HY000)的解決方案
[3]MySQL 查看用戶授予的權限
[4]mysql root權限優化后沒有grant權限
[5]mysql8使用grant授權修改
?
?
?
總結
以上是生活随笔為你收集整理的mysql8出现1045报错+常用的加密plugin汇总的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 智力大冲浪-贪心
- 下一篇: mysql8報錯解決方案彙總(持續更新中