artisan - SQLSTATE[HY000] [2003] Can't connect to MySQL server on '127.0.0.1'

馋奶兔 提交于 2019-12-24 13:46:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!