blob: de60dca16cb4e37ec30025842682920ea9e6a55c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  | 
# SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed
> Mon 14th December 2020 By David T. Sadler.
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 introduced 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
```
### Links
=> https://github.com/laravel/laravel/commit/a895748980b3e055ffcb68b6bc1c2e5fad6ecb08#diff-a3046da0d15a27e89f2afe639b25748a7ad4d9290af3e7b1b6c1a5533c8f0a8cL11 Commit that changed .env.example.
=> https://laravel.com/docs/8.x/sail/ Laravel Sail
=> /posts/larvel/ Laravel - Read More Posts.
I don't have comments as I don't want to manage them. You can however contact me at the below address if you want to.
=> mailto:david@davidtsadler.com Email david@davidtsadler.com
### License
=> https://creativecommons.org/licenses/by-sa/4.0/ The contents of this site is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Copyright © 2021 David T. Sadler.
=> / Return to Homepage.
  |