ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)

匿名 (未验证) 提交于 2019-12-03 00:50:01

问题:

I use the following command:

mysql -u root -h 127.0.0.1 -p 

and the error message is :

ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111) 

Who can help me to fix it?

回答1:

If you are using ubuntu, you have to use the following steps to avoid this error:

  1. run the command vim /etc/mysql/my.cnf
  2. comment bind-address = 127.0.0.1 using the # symbol
  3. restart your mysql server once.

Update

In Step 1, if you cannot find bind-address in the my.cnf file, look for it in /etc/mysql/mysql.conf.d/mysqld.cnf file.



回答2:

Try localhost instead of 127.0.0.1 to connect or in your connection-config. Worked for me on a Debian Squeeze Server



回答3:

In my case (remote connnection) helped turning off firewall on server.

service iptables stop 


回答4:

This happens when you forget to start the database before connecting to it:

mysql.server start 

then

mysql -u root -p -h 127.0.0.1 


回答5:

look at the my.cnf file, if there contain [client] section, and the port is other than real listen port (default 3306), you must connect the server with explicit parameter -P 3306, e.g.

mysql -u root -h 127.0.0.1 -p -P 3306



回答6:

This problem may occur because your MySQL server is not installed and running. To do that start command prompt as admin and enter command:

"C:\Program Files (x86)\MySQL\MySQL Server 5.1\bin\mysqld" --install 

If you get "service successfully installed" message then you need to start the MySQL service. To do that: go to Services window (Task Manager -> Services -> Open Services) Search for MySQL and Start it from the top navigation bar. Then if try to open mysql.exe it will work.



回答7:

You need to change the bind-address parameter to 127.0.0.1 in the mysql config file (my.ini or my.cnf) or use the one that is defined there.

If that doesn't work you should check that the mysql service is actually running.



回答8:

Incase you are running on a non-default port, you may try using --port= provided --skip-networking is not enabled.



回答9:

I just have this problem.... running in Win7 and wamp server ... after reading this

Found that Antivirus Firewall has caused the problem.



回答10:

I was also facing the same issue. The following helped me fix the problem go to control panel-> Administrative tools-->services inside this you will most certainly see the MySQL servce: right click and say start(force start).



回答11:

i just restart my mysql server and the problem solved in windows net stop MySQL then net start MySQl ubuntu linux sudo service start mysql



回答12:

I changed the installation directory on re-install, and it worked.



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