はじめに
こんなエラーでた。
terminal
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+37 vendor frames
38 artisan:37
Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
結論
configがしっかり反映されていなかったので、以下のコマンドでconfigに.env
の内容を反映させると解消された。
terminal(Docker内)
$ php artisan config:clear
対処法
php artisan tinker
で.envの内容が反映されているか確かめる
terminal(Docker内)
$ php atisan tinker
>> config('database')
=> [
"default" => "mysql",
"connections" => [
"sqlite" => [
"driver" => "sqlite",
"url" => null,
"database" => "xxx",
"prefix" => "",
"foreign_key_constraints" => true,
],
"mysql" => [
"driver" => "mysql",
"url" => null,
"host" => "mysql", // この辺に注目
"port" => "3306",
"database" => "xxx", // この辺に注目
"username" => "xxx", // この辺に注目
"password" => "xxx", // この辺に注目
"unix_socket" => "",
"charset" => "utf8mb4",
"collation" => "utf8mb4_unicode_ci",
"prefix" => "",
"prefix_indexes" => true,
"strict" => true,
"engine" => null,
"options" => [],
],
# 以下省略
configに、.env
の内容が反映されてなかったら結論で示したコマンドでどうにかなるかも(自分は解決した)