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

做~自己de王妃 提交于 2019-11-26 03:49:15

问题


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(if there is no replication enabled):

  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.

Update in case of MySQL replication enabled

Try to connect MySQL server on IP for which MySQL server is bind in 'my.cnfinstead oflocalhost or 127.0.0.1`.




回答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:


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



回答4:


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

service iptables stop



回答5:


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.




回答6:


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




回答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=<port num> 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:


For Docker users - When trying to connect local sql using mysql -u root -h 127.0.0.1 -p and your database is running on Docker container, make sure the mysql service is up and running (verify using docker ps and also check that you are in the right port as well) , if the container is down you'll get connection error.

Best practice is to set the ip's in /etc/hosts on your machine:

127.0.0.1 db.local

and running it by mysql -u root -h db.local -p




回答12:


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




回答13:


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



来源:https://stackoverflow.com/questions/1673530/error-2003-hy000-cant-connect-to-mysql-server-on-127-0-0-1-111

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