简体   繁体   中英

Laravel migration "No such file or directory"

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)

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

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', '')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM