XAMPP or MAMP – Can’t connect to mysql

You’ll need to update your DB config file…

What worked for me was adding this:

'mysql' => [
 'driver' => 'mysql',
 'host' => env('DB_HOST', 'localhost'),
 'database' => env('DB_DATABASE', 'db_name'),
 'username' => env('DB_USERNAME', 'db_user'),
 'password' => env('DB_PASSWORD', 'db_password'),
 'unix_socket' => '/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock',
 'charset' => 'utf8',
 'collation' => 'utf8_unicode_ci',
 'prefix' => '',
 'strict' => false,
 'options' => [

Here’s one other solution:

I was getting some similar error and ended up here. I am using OSX 10.9.5. This solved my problems (hope it helps someone).

1) sudo mkdir /var/mysql
2) sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock

More informations: http://glidingphenomena.blogspot.com.br/2010/03/fixing-warning-mysqlconnect-cant.html


NOTE: Replace /var/mysql/mysql.sock with the path to your actual mysql.sock file (w XAMPP, it would be /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock)