Laravel 5.1 - Connecting to MySQL Database (MAMP)

On mac or unix you have to include the socket path in the configuration database.php file

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


It was pretty simple for me, I added :8889 to the localhost in the .env file.

DB_HOST=localhost:8889

This is because in the MAMP preferences, :8889 is the default port.


The most important thing for me was defining the UNIX socket. Because I have another MYSQL on my machine - Laravel was trying to connect to a database in that MYSQL process.

Defining the UNIX for the MAMP database to be used worked perfectly. Try adding this to your MYSQL configuration in database.php

   'mysql' => [
      'driver' => 'mysql',
      'host' => env('DB_HOST', '127.0.0.1'),
      'port' => env('DB_PORT', '3306'),
      'database' => env('DB_DATABASE', 'forge'),
      'username' => env('DB_USERNAME', 'forge'),
      'password' => env('DB_PASSWORD', ''),
      'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
      'charset' => 'utf8mb4',
      'collation' => 'utf8mb4_unicode_ci',
      'prefix' => '',
      'strict' => true,
      'engine' => null,
    ],