-1

When I am writing the php artisan migrate command then I have see something like this:-

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

    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:\Users\NaimBiswas\Desktop\Laravel\four\crudtwo\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:\Users\NaimBiswas\Desktop\Laravel\four\crudtwo\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70
      PDO::__construct("mysql:host=mysql;port=3306;dbname=crudtwo", "root", "", [])

After few hour I have find a solution. The solution is just remove DB_HOST=mysql from the .env file Now my question is can anyone explain more about this, and why this error came, and why it's solve after remove DB_HOST=mysql.

Naim Biswas
  • 78
  • 1
  • 6

1 Answers1

7

The error PDO::__construct("mysql:host=mysql;port=3306;dbname=crudtwo", "root", "", []) shows that you have a wrong entry in .env file

Change the DB_HOST in .env file as

//Change
DB_HOST=mysql

//To
DB_HOST=127.0.0.1
Donkarnash
  • 12,433
  • 5
  • 26
  • 37