Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No such file or directory" or "No such host is known" when running migrations

I deleted the migrations table from a Laravel 5.4 database named laravel. When I run php artisan migrate:install, I get this error:

[Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = laravel     and table_name = migrations) 

I deleted and recreated the database. I also ran composer update. No luck. I can run the command in phpMyAdmin and create the table manually.

This problem sometimes also manifests itself with similar 2002 errors:

[Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known. (SQL: select * from information_schema.tables where table_schema = laravel     and table_name = migrations and table_type = 'BASE TABLE') 
[Illuminate\Database\QueryException] SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known (SQL: select * from information_schema.tables where table_schema = laravel     and table_name = migrations and table_type = 'BASE TABLE') 
like image 275
Jay Bienvenu Avatar asked Sep 25 '17 14:09

Jay Bienvenu


2 Answers

If you are using localhost as your DATABASE_HOST in the .env file, change it to 127.0.0.1, then run php artisan config:clear and now try php artisan migrate:install again.

like image 198
Camilo Avatar answered Oct 10 '22 14:10

Camilo


Here's what I recommend for .env file:

DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 

Then in Database.php add folder location:

'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'), 

Finally, try:

php artisan config:clear php artisan migrate:install 
like image 20
kaleazy Avatar answered Oct 10 '22 13:10

kaleazy