“SQLSTATE[HY000] [2002] No such file or directory” error when migrating table in Laravel

社会主义新天地 提交于 2019-12-04 18:13:35

try 127.0.0.1 instead of localhost in your .env file. It works for me :)

Walter

Add mysql.sock path in database.php file like below example

'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',

Eample

'mysql' => [
        'driver' => 'mysql',
        'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '8889'),

PDOException SQLSTATE[HY000] [2002] No such file or directory

Noman Ur Rehman

This seems to be an issue with the socket file. Please let me know if this helps Starting with Zend Tutorial - Zend_DB_Adapter throws Exception: "SQLSTATE[HY000] [2002] No such file or directory"

Okay, this is might be a special case to me however I had this issue.

I moved my files from a Laragon based server to a mamp based server on a different machine. I had this error for days and I only received this error when running php artisan migrate and not when loading the page. When loading the page i received table not found which is understandable as the table isn't there.

After quite some time I just though of running composer update and then it fixed the error and worked for me. Not sure if this helps anyone but I came back to this post in case it somehow does.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!