1

I started working with Laravel recently and followed every step from this tutorial: https://www.toptal.com/laravel/restful-laravel-api-tutorial

For now I create the model and configured the .env and database files.

.env file:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=bank
DB_USERNAME=root
DB_PASSWORD=

For me everything seems correct, MyPhpAdmin is running and I have added a bank database to it.

But every time I try to migrate I get the following error:

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

JustCarty
  • 3,839
  • 5
  • 31
  • 51
marisu
  • 11
  • 1
  • 3

2 Answers2

1

This looks unrelated to Laravel, I think it's to do with PHP not being able to connect to MySQL correctly. See here - PHP - MySQL connection not working: 2002 No such file or directory

George Hanson
  • 2,940
  • 1
  • 6
  • 18
  • I changed my default socket in the php.ini file to pdo_mysql.default_socket=/opt/lampp/var/mysql/mysql.sock and restarted my Apache but its still not working :( – marisu Oct 11 '18 at 13:38
0

I add DB_SOCKET in .env file refer to my.cnf (socket) then run php artisan migrate. It works!

DB_SOCKET=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

And double check your config/database.php, comment or delete if there are other unix_socket except this 'unix_socket' => env('DB_SOCKET', '')

Nurkartiko
  • 183
  • 2
  • 10