報錯之後嘗試各種方式修改密碼都失敗,查詢後才發現是密碼沒有符合標準
Attempt to fix the "Access denied for user root@localhost" by changing the authentication method from auth_socket to mysql_native_password and setting the password for the root user. This method is less secure than auth_plugin, so it is necessary to set a strong password.
就是密碼需要符合一定的複雜性原則,例如包含大小寫字母和數字的組合最小8位等
$sudo mysql -u root
mysql> use mysql;
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'strong-password';
FLUSH PRIVILEGES;
完成後測試
mysql -u root -p
Enter password:輸入設定的密碼
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.43-0ubuntu0.22.04.2 (Ubuntu)