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' => '', ),
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!