使用homestead環境開發,.env配置檔案如下:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=33060
DB_DATABASE=xxx
DB_USERNAME=homestead
DB_PASSWORD=secret
報錯如下:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `users` where `id` = 1 limit 1)
網上搜尋解決方案:
將 DB_HOST=127.0.0.1 更改為 DB_HOST=localhost
上述錯誤成功解決;但是執行 php artisan migrate
報錯
PDOException : SQLSTATE[HY000] [2006] MySQL server has gone away
解決方案:
DB_CONNECTION=mysql
DB_HOST=homestead.test // 你的.host檔案中對映的域名
#DB_PORT=33060 // 埠註釋掉
DB_DATABASE=xxx
DB_USERNAME=homestead
DB_PASSWORD=secret