I went through the laravel to-do app and am stuck at the php artisan migrate part. I know this question has been posted many times here already but I feel like I've tried many suggestions that just aren't working--changing the host to localhost and 127.0.0.1, generating the key for the .env file, adding in a socket, forcing the migration, etc. Below is a screenshot of my .env and database files for your reference. Any assistance is greatly appreciated!
3 Answers
So because you're using MAMP, there's a few caveats which are probably not clear, such as MAMP not using a normal UNIX Socket.
But to fix your problem, you'll need to do the following in your database config file, replace unix_socket
with this:
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
You may also have to run:
php artisan cache:clear
Incase your config files have been cached previously.

- 996
- 1
- 6
- 11
-
I changed the unix_socket with what you suggested above and also cleared the cache but am still getting the error message -- [PDOException] SQLSTATE[HY000] [2002] No such file or director – ele Aug 05 '17 at 05:30
-
@emily try techytimo solution by putting the path in .env file – Jul 18 '18 at 15:36
Had this same issue since I am using MAMP. I am on laravel 5.5 so my database.php has this line under the mysql
directive:
'unix_socket' => env('DB_SOCKET', ''),
The solution was to add the DB_SOCKET option which was missing on the environment file:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock

- 4,198
- 6
- 49
- 59
I experienced the same problem using Laravel 5.7.3 with XAMPP for OS X (not XAMPP-VM) and managed to solve this by referring to Kyo's solution in this post.
I updated line 49 in config/database.php:
'unix_socket' => env('DB_SOCKET', ''),
with
'unix_socket' => env('DB_SOCKET', '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock'),
I also tried TechyTimo's solution above and this worked for me as well. I assume it would be better to use this solution since all configurations are kept in one file.

- 1
- 1
- 1
-
i want to try this solution @Claret15 mentions since im on xampp but mysql socket file is missing for me. i was expecting to find it here: /opt/lampp/var/mysql – Screwtape007 Jun 07 '20 at 00:07