Mysql 8.0 遇到用遇到的幾個問題及解決辦法

2059 - Authentication plugin ‘caching_sha2_password’

在這裏插入圖片描述

問題原因,Mysql8.0開始加密用的是caching_sha2_password,之前用的是mysql_native_password

解決辦法,更改加密規則

mysql -uroot -ppassword #登錄

use mysql; #選擇數據庫
# password換成你的密碼,遠程連接請將'localhost'換成'%'
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密碼' PASSWORD EXPIRE NEVER; #更改加密方式
# password換成你的密碼
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密碼'; #更新用戶密碼

FLUSH PRIVILEGES; #刷新權限

客戶端遠程連接時

在這裏插入圖片描述


mysql>use mysql;
# 創建遠程連接%
mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.02 sec)
# 修改遠程連接的加密方式爲mysql_native_password
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '你的密碼!';
Query OK, 0 rows affected (0.01 sec)
# 刷新權限
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
# 查看用戶,下面這個就是爲遠程創建的遠程
mysql> select Host,User,plugin from mysql.user;
 %             | root             | mysql_native_password 

Linux 登錄時,ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO/YES)

問題原因,本地密碼不小心更新了或者忘記了
解決辦法,停掉數據庫,修改my.cnf配置文件

# 停掉MySQL服務
service mysqld stop
# 查看狀態
service mysqld status
#查找my.cnf
whereis my.cnf
# 編輯文件
vim my.cnf
## !添加跳過密碼驗證
skip-grant-tables
# 重啓MySQL服務
service mysqld restart
## !輸入進入mysql命令後,直接回車進入
mysql -u root -p
# 更新密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密碼';
## 刷新權限,否則會報錯1290,解決辦法見下面
flush privileges;
## !記得回去把跳過密碼驗證刪了
#skip-grant-tables
# 重啓MySQL服務
 service mysqld restart
#用新密碼登錄
mysql -u root -p

ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

問題原因,增加了跳過密碼,沒有刷新權限
解決辦法,MySQL裏執行

flush privileges;

update user set password=password(“root”) where user=“root”; 報錯

mysql> update user set password=password("你的密碼") where user="root";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '("你的密碼") where user="root"' at line 1

把password改爲authentication_string後,發現還是提示錯誤
mysql> update user set authentication_string=password("root") where user="root";
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near '("123456") where user="root"' at line 1

問題原因,語句格式錯誤,但是網上大多數都是這幾個更新語句
後面查看*https://blog.csdn.net/weixin_43645330/article/details/83869490*找到了原因

# 更換語句
mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密碼';
Query OK, 0 rows affected (0.01 sec)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章