问题
I ran the command: "php artisan migrate" and got the error message displayed below:
[PDOException]
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1' (111)
What's the problem and how do I fix it?
回答1:
there could be following possibilities -
- you haven't set the right credentials for mysql access in your .env file which is located at the root of your application.
Solution - Open .env file in your preferred editor and check if all the mysql access credentials are correct.
its something like -
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=[your db name here]
DB_USERNAME=[db user here]
DB_PASSWORD=[password]
- the user credentials doesn't have access to mysql or database that you mentioned in .env file
Solution - use any mysql interface (phpmyadmin, workbench..etc) to check if the user that you mentioned in .env file have enough access to connect.
- mysql is not running - based on your OS(windows, ubuntu..) check if mysql is running
来源:https://stackoverflow.com/questions/37005118/artisan-sqlstatehy000-2003-cant-connect-to-mysql-server-on-127-0-0-1