Home > Database > Mysql Tutorial > body text

How to Fix \'SQLSTATE[HY000] [2002] No such file or directory\' Error When Migrating Laravel on a Mac Using MAMP?

Patricia Arquette
Release: 2024-10-31 16:02:06
Original
550 people have browsed it

How to Fix

Setting up Laravel on a Mac: Resolving the "No such file or directory" Error with php artisan migrate

While setting up Laravel on a Mac using MAMP, a developer encountered the error "SQLSTATE[HY000] [2002] No such file or directory" when executing php artisan migrate. This error indicates that the system is unable to locate the MySQL database.

To resolve this issue, it is necessary to configure the database connection properly. In the config/database.php file, the 'mysql' array should include a 'unix_socket' key that specifies the path to the mysql.sock file. In the case of MAMP, this path is typically '/Applications/MAMP/tmp/mysql/mysql.sock'.

    'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'localhost',
        'unix_socket'   => '/Applications/MAMP/tmp/mysql/mysql.sock',
        'database'  => 'database',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
    ),
Copy after login

By including this 'unix_socket' key, the system will be able to establish a proper connection to the MySQL database, allowing php artisan migrate to execute successfully.

The above is the detailed content of How to Fix \'SQLSTATE[HY000] [2002] No such file or directory\' Error When Migrating Laravel on a Mac Using MAMP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!