1. 程式人生 > 其它 >Laravel連線MySQL 8.0.11 遇到的一些坑

Laravel連線MySQL 8.0.11 遇到的一些坑

1. Authentication Type

相信很多朋友在mysql升級8.0.11後發現數據庫連接出現了問題
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

原因在於:
使用者的Authentication type預設為caching_sha2_password,導致資料庫連線錯誤,丟擲如下異常:
Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

解決方式:
修改密碼認證方式
ALTER USER 'YOURUSERNAME'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOURPASSWORD';

2、刪除了 NO_AUTO_CREATE_USER 模式

在 5.7.*的日誌中提到已廢除該模式,在8.0.11中刪除了,遷移時會丟擲如下異常:
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1231 Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'

解決方案:將config/database.php配置檔案中mysql 的strict的值改為false即可!

轉載來自:https://laravel-china.org/articles/10736/some-craters-in-mysql-8011