This article mainly introduces how Laravel executes the migrate command prompt: Nosuchfileordirectory solution, and analyzes the causes and related solutions for errors when executing the migrate command, for more information about how to execute the migrate command in Laravel, see the following example: No such file or directory. We will share this with you for your reference. The details are as follows:
An error is reported when you use the Laravel command line tool to perform database migration. the error mysql 2002 is displayed,
Check the database configuration. The website front-end can also be opened, indicating that the database can be connected. why?
There are two solutions in Laravel5:
1. add a database configuration item
'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_general_ci', 'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock', 'prefix' => 'laravel_', 'strict' => false,],
Here, we add unix_socket, which is the MAMP environment installed on the Mac of the local machine. The path is/Applications/MAMP/tmp/mysql. to view your path, enter the following command in mysql:
Show variables like '% sock % ';
As shown in:
2. Modify. env configuration
This method can only be temporary modification, so that migrate can be executed, and then it must be changed back.
DB_HOST=localhostDB_CONNECTION=mysqlDB_DATABASE=laravelDB_USERNAME=rootDB_PASSWORD=tantengDB_PORT=8889
The temporary modification method is to change DB_HOST to localhost: 8889, that is, add the port number, and then use the artisan command of Laravel5 to execute the migrate operation. However, after the operation is complete, you need to change it back to the previous method, otherwise, the front-end page of the website cannot be connected to the database. the error message "SQLSTATE [HY000] [2005] Unknown MySQL server host" localhost: 8889 "(0) is displayed)
Now, the migrate error of Laravel5 is solved.