3

After new laravel8 jetstream with livewire fresh installed when I run the command php artisan migrate then it gives the error on my terminal

  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.  (SQL: select * from information_schema.tables where table_schema = lweb and table_name = migrations and table_type = 'BASE TABLE')

  at C:\xampp\htdocs\liveweb\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▕

  1   C:\xampp\htdocs\liveweb\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDOException::("PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. ")

  2   C:\xampp\htdocs\liveweb\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct("mysql:host=mysql;port=3306;dbname=lweb", "root", "", [])
PS C:\xampp\htdocs\liveweb> 
3
  • 3
    Check DB_HOST entry in your .env file and config/database.php for the database you are using, both places the value should be 127.0.0.1 if the database server is also running on the same machine as the webserver
    – Donkarnash
    Dec 9, 2020 at 15:42
  • you havent started apache and mysql yet
    – BillJustin
    Dec 9, 2020 at 15:49
  • 1
    PDO::__construct("mysql:host=mysql;port=3306;dbname=lweb", "root", "", []) in the error shows that you have DB_HOST=mysql in .env file which can't be resolved to a host address - host means the ip address of the server hosting the database
    – Donkarnash
    Dec 9, 2020 at 15:56

1 Answer 1

21

Problem solve just remove DB_HOST=mysql

DB_CONNECTION=mysql
DB_HOST=localhost
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=lweb
DB_USERNAME=root
DB_PASSWORD=
  

To

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=lweb
DB_USERNAME=root
DB_PASSWORD=
4
  • 2
    I hope this could be helpful for those who have gone through the solution and not yet succeeded. I had similar problem and tried to change the DB_HOST localhost to 127.0.0.1 also with the name of the container/db host (as mentioned in docker-compose), yet did not help. So I updated my .env file like this: DB_CONNECTION=mysql DB_HOST=host.docker.internal DB_PORT=3308 or any other port DB_DATABASE=your_database_name DB_USERNAME=your_user_name DB_PASSWORD=your_password you could give a try for this in case other option are not working. Hope it helps! Cheers!
    – vins
    Jun 13, 2022 at 18:36
  • Thanks @vins, your answer helped a lot, I've been searching this for hours.
    – amorim
    Dec 5, 2022 at 7:14
  • @vins You should post your comment as an answer instead. It's helped me with my Laravel Sail project. Jan 6 at 15:44
  • @Shockch4rge thank you for the support :). I would have answered but its not allowed probably the topic has been closed. Well hopefully someone landing here would look into the comments as well like you did and try my suggestion
    – vins
    Jan 13 at 10:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.