diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2020-12-11 17:28:33 +0000 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2020-12-11 17:28:33 +0000 |
| commit | 1ccd513996594511b0171d8620d59fde503d4b02 (patch) | |
| tree | 73a044d7d76ce2d13c29f69d49ad6963c71bca19 | |
| parent | 9e890ff565edeac4334f6af8362b5534be24b5be (diff) | |
Add SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed
| -rw-r--r-- | source/_posts/installing_laravel_homestead_in_arch_linux.md | 2 | ||||
| -rw-r--r-- | source/_posts/sqlstate_hy000_2002_php_network_getaddresses_getaddrinfo_failed.md | 45 |
2 files changed, 46 insertions, 1 deletions
diff --git a/source/_posts/installing_laravel_homestead_in_arch_linux.md b/source/_posts/installing_laravel_homestead_in_arch_linux.md index 1b78b8e..0488747 100644 --- a/source/_posts/installing_laravel_homestead_in_arch_linux.md +++ b/source/_posts/installing_laravel_homestead_in_arch_linux.md @@ -2,7 +2,7 @@ extends: _layouts.post section: content title: Installing Laravel Homestead in Arch Linux -date: 2020-12-14 +date: 2020-12-21 description: This is a guide to how I install Laravel Homestead in Arch Linux tags: [Arch, Laravel] --- diff --git a/source/_posts/sqlstate_hy000_2002_php_network_getaddresses_getaddrinfo_failed.md b/source/_posts/sqlstate_hy000_2002_php_network_getaddresses_getaddrinfo_failed.md new file mode 100644 index 0000000..f217c93 --- /dev/null +++ b/source/_posts/sqlstate_hy000_2002_php_network_getaddresses_getaddrinfo_failed.md @@ -0,0 +1,45 @@ +--- +extends: _layouts.post +section: content +title: 'SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed' +date: 2020-12-14 +description: What to do if you get this error when doing a Laravel migration. +tags: [Laravel] +--- + +One of the first things you do when creating a new Larvel application is run *php artisan migrate* to create the application database tables. However you may come across the below message. + +```shell +$ php artisan migrate + +Illuminate\Database\QueryException + + SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = testsite and table_name = migrations and table_type = 'BASE TABLE') + + at vendor/laravel/framework/src/Illuminate/Database/Connection.php:678 + 674▕ // If an exception occurs when attempting to run a query, we'll format the error + 675▕ // message to include the bindings with SQL, which will make this exception a + 676▕ // lot more helpful to the developer instead of just the database's errors. + 677▕ catch (Exception $e) { + 678▕ throw new QueryException( + 679▕ $query, $this->prepareBindings($bindings), $e + 680▕ ); + 681▕ } + 682▕ + + +33 vendor frames + 34 artisan:37 + Illuminate\Foundation\Console\Kernel::handle() +``` + +The cause of this issue is due to a [change](https://github.com/laravel/laravel/commit/a895748980b3e055ffcb68b6bc1c2e5fad6ecb08#diff-a3046da0d15a27e89f2afe639b25748a7ad4d9290af3e7b1b6c1a5533c8f0a8cL11) to the *.env.example* file. + +This changed the environment variable *DB_HOST* from *127.0.0.1* to *mysql*. The reason for this change is to support [Laravel Sail](https://laravel.com/docs/8.x/sail) which is a Docker development environment for Laravel. + +The change means your Laravel application will try and connect to a database server with the hostname of *mysql*. Unless this exists then the application can't connect. + +To resolve the issue just change the value back to *127.0.0.1* + +```shell +DB_HOST=127.0.0.1 +``` |
