Search code examples
laravelmamp

Laravel Artisan Serve cannot detect mysql when using Mamp


Sometimes I can't run php artisan migrate if I'm using mamp. It yield this error:

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

Why would this be happening?


Solution

  • Sometimes you have to exclusively tell Laravel where the unix_socket location. In case of Mamp, you should add this line to your mysql config:

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

    If you are using xampp, the location would be C:/xampp/xamppfiles/var/mysql/mysql.sock.

    To get path to your active socket file, try login to your mysql server and run status command.