Black Friday sale is now on! 50% off Laravel: The Modular Way. Learn more

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 Book by David Carr

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

    Subscribe to my newsletter

    Subscribe and get my books and product announcements.

    © 2009 - 2022 DC Blog. All code MIT license. All rights reserved.