Home > Article > Backend Development > Laravel executes the migrate command prompt: No such file or directory solution, laravelmigrate_PHP tutorial
This article describes the example of Laravel executing the migrate command prompt: No such file or directory solution. Share it with everyone for your reference, the details are as follows:
Today, when using the Laravel command line tool to perform database migration operations, an error occurred, prompting a mysql 2002 error, as shown in the figure:
It is correct to check the database configuration. The front desk of the website can also be opened, indicating that it can be connected. What is the reason?
In Laravel5, there are two ways to solve it:
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, ],
The added item here is unix_socket, the MAMP environment installed on the local Mac. The path is /Applications/MAMP/tmp/mysql/mysql.sock. The way to check your own path is to enter the following command in mysql to see it. :
show variables like '%sock%';
As shown below:
2. Modify .env configuration
This method can only be a temporary modification so that migrate can be executed, and then it must be changed back.
DB_HOST=localhost DB_CONNECTION=mysql DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD=tanteng DB_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 perform the migrate operation. However, after the operation is completed, you must change it back to the previous writing method, otherwise the website front desk The page cannot be opened and cannot be connected to the database, and the error message is: SQLSTATE[HY000] [2005] Unknown MySQL server host 'localhost:8889' (0)
Okay, this solves the problem of error reporting using Laravel5's migrate.
Reprinted from: Xiaotan Blog http://www.tantengvip.com/2015/12/laravel-migrate-mysql-2000/
Readers who are interested in more information about Laravel can check out the special topics on this site: "Introduction and Advanced Tutorial on Laravel Framework", "Summary of PHP Excellent Development Framework", "Basic Tutorial on Getting Started with Smarty Templates", "php Date and Time" Usage Summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php mysql database operation introductory tutorial" and "php common database operation skills summary"
I hope this article will be helpful to everyone’s PHP program design based on the Laravel framework.