前提
Windows 10 Pro 64bit環境上にLaravelをインストールし、
Docker上にMySQLの環境を作りこれを接続しようとしています。
php artisan migrate
を実行したところ下記1つ目のエラーが発生しました。
.env
のDB_HOST=127.0.0.1
をDB_HOST=mysql
に書き換えると下記2つ目のエラーが発生しました。
実現したいこと
php artisan migrate
をエラーなく動作させ環境構築を完了させる。
発生している問題・エラーメッセージ
1つ目のエラー
1C:\Users\admin\AppData\Original\Git\PLF\pl-f>php artisan migrate 2 3 Illuminate\Database\QueryException 4 5 SQLSTATE[HY000] [2002] 対象のコンピューターによって拒否されたため、接続できませんでした。 (SQL: select * from information_schema.tables where table_schema = plf and table_name = migrations and table_type = 'BASE TABLE') 6 7 at C:\Users\admin\AppData\Original\Git\PLF\pl-f\vendor\laravel\framework\src\Illuminate\Database\Connection.php:742 8 738▕ // If an exception occurs when attempting to run a query, we'll format the error 9 739▕ // message to include the bindings with SQL, which will make this exception a 10 740▕ // lot more helpful to the developer instead of just the database's errors. 11 741▕ catch (Exception $e) { 12 ➜ 742▕ throw new QueryException( 13 743▕ $query, $this->prepareBindings($bindings), $e 14 744▕ ); 15 745▕ } 16 746▕ } 17 18 1 C:\Users\admin\AppData\Original\Git\PLF\pl-f\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 19 PDOException::("SQLSTATE[HY000] [2002] 対象のコンピューターによって拒否されたため、接続できませんでした。") 20 21 2 C:\Users\admin\AppData\Original\Git\PLF\pl-f\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 22 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=plf", "root", "password", []) 23
2つ目のエラー
1C:\Users\admin\AppData\Original\Git\PLF\pl-f>php artisan migrate 2 3 Illuminate\Database\QueryException 4 5 SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: ���̂悤�ȃz�X�g�͕s���ł��B (SQL: select * from information_schema.tables where table_schema = plf and table_name = migrations and table_type = 'BASE TABLE') 6 7 at C:\Users\admin\AppData\Original\Git\PLF\pl-f\vendor\laravel\framework\src\Illuminate\Database\Connection.php:742 8 738▕ // If an exception occurs when attempting to run a query, we'll format the error 9 739▕ // message to include the bindings with SQL, which will make this exception a 10 740▕ // lot more helpful to the developer instead of just the database's errors. 11 741▕ catch (Exception $e) { 12 ➜ 742▕ throw new QueryException( 13 743▕ $query, $this->prepareBindings($bindings), $e 14 744▕ ); 15 745▕ } 16 746▕ } 17 18 1 C:\Users\admin\AppData\Original\Git\PLF\pl-f\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 19 PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo for mysql failed: ���̂悤�ȃz�X�g�͕s���ł��B ") 20 21 2 C:\Users\admin\AppData\Original\Git\PLF\pl-f\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 22 PDO::__construct("mysql:host=mysql;port=33306;dbname=plf", "root", "password", []) 23
試したこと
1つ目のエラーが発生したあと、.env
の
_.env
1DB_CONNECTION=mysql 2DB_HOST=127.0.0.1 3DB_PORT=3306 4DB_DATABASE=plf 5DB_USERNAME=root 6DB_PASSWORD=password
の値をチェックしました。また、念のためにとdatabase.php
の
database.php
1 'mysql' => [ 2 'driver' => 'mysql', 3 'url' => env('DATABASE_URL'), 4 'host' => env('DB_HOST', '127.0.0.1'), 5 'port' => env('DB_PORT', '3306'), 6 'database' => env('DB_DATABASE', 'plf'), 7 'username' => env('DB_USERNAME', 'root'), 8 'password' => env('DB_PASSWORD', 'password'),
の値も書き換えました。
php artisan cache:clear
を実行し再度php artisan migrate
を試してみましたが1つ目のエラーと同じエラーになりました。
次に、.env
のDB_HOST
をMySQLのコンテナ名のmysql
に変更し、php artisan cache:clear
を実行し再度php artisan migrate
を試してみましたが2つ目のエラーと同じエラーになりました。
docker volume prune
を試してみましたが、削除されたファイルは0Bで、php artisan cache:clear
を実行し再度php artisan migrate
を試してみましたが2つ目のエラーと同じエラーになりました。
補足情報(FW/ツールのバージョンなど)
- Windows 10 Pro 64bit 19043.1706
- PHP VS16 x64 Thread Safe (2022-May-11 09:29:42)
- Composer v2.3.7
- Laravel Framework 9.16.0
- Docker version 4.3.2
- MySQL 8.0
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/06/15 07:30
2022/06/15 07:45