LoginSignup
9
1

More than 1 year has passed since last update.

SQLSTATE[HY000] [2002] Connection refused が出た時の対処方法

Posted at

エラー内容

このような内容でした

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:712
    708▕         // If an exception occurs when attempting to run a query, we'll format the error
    709▕         // message to include the bindings with SQL, which will make this exception a
    710▕         // lot more helpful to the developer instead of just the database's errors.
    711▕         catch (Exception $e) {
  ➜ 712▕             throw new QueryException(
    713▕                 $query, $this->prepareBindings($bindings), $e
    714▕             );
    715▕         }
    716▕     }

      +36 vendor frames 
  37  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

対処法

php artisan tinkerで.envファイルの内容がちゃんと反映されてるか確かて見たところ、反映されていなかったためこれが原因だったようです。

root@8dae87ded68a:/var/www/app# php artisan tinker
Psy Shell v0.11.1 (PHP 8.0.15 — cli) by Justin Hileman
>>> config('database')
=> [
    ../
       "mysql" => [
         "driver" => "mysql",
         "url" => null,
         "host" => "127.0.0.1", #要注意
         "port" => "3306",
         "database" => "laravel",#要注意
         "username" => "root",#要注意
         "password" => "",#要注意
         "unix_socket" => "",
         "charset" => "utf8mb4",
         "collation" => "utf8mb4_unicode_ci",
         "prefix" => "",
         "prefix_indexes" => true,
         "strict" => true,
         "engine" => null,
         "options" => [],
       ],
../

なので.envファイルを適用させればいいのですが、php artisan config:clearコマンドで内容を適用させればいらしいんですが、私の場合これではうまく適用されずrm app/.envでファイルを削除させもう一度復元させたら成功しました。

まとめ

ファイルを消さないと適用されないところを治したい

9
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
1