Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

Using MAMP and dealing with the error: mysql No such file or directory

David Carr

Nova Framework

I’ve got a fresh install of Nova Framework installed and decided to use MAMP as my server and database management, one problem that can happen is when running Nova’s CLI forge commands can fail giving this error:

{"error":{"type":"PDOException","message":"SQLSTATE[HY000] [2002] No such file or directory","file":"novaframework\/vendor\/nova-framework\/system\/src\/Database\/Connector.php","line":62}}

This happens when terminal cannot connect to mysql in MAMP’s case the solution is to specify the path to the mysql.sock in app/Config/Database.php add this to the mysql array:

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

So it looks like:

'mysql' => array(
      'driver'    => 'mysql',
      'hostname'  => 'localhost',
      'database'  => 'nova',
      'username'  => 'root',
      'password'  => 'root',
      'prefix'    => PREFIX,
      'charset'   => 'utf8',
      'collation' => 'utf8_general_ci',
      'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
),

That’s it! now terminal can connect to mysql and use the forge commands.

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.