错误 2003 (HY000):无法连接到“127.0.0.1”上的 MySQL 服务器 (111)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1673530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
提问by Charlie Epps
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?
谁能帮我解决?
回答by Justin Vincent
If you are using ubuntu
, you have to use the following steps to avoid this error(if there is no replication enabled):
如果您正在使用ubuntu
,则必须使用以下步骤来避免此错误(如果没有启用复制):
- run the command
vim /etc/mysql/my.cnf
- comment
bind-address = 127.0.0.1
using the # symbol - restart your mysql server once.
- 运行命令
vim /etc/mysql/my.cnf
bind-address = 127.0.0.1
使用# 符号注释- 重新启动您的 mysql 服务器一次。
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.
在步骤 1 中,如果bind-address
在my.cnf
文件中找不到,请在文件中查找/etc/mysql/mysql.conf.d/mysqld.cnf
。
Update in case of MySQL replication enabled
在启用 MySQL 复制的情况下更新
Try to connect MySQL server on IP
for which MySQL server is bind in 'my.cnfinstead of
localhost or 127.0.0.1`.
尝试连接IP
在“my.cnf instead of
localhost 或 127.0.0.1 ”中绑定了 MySQL 服务器的 MySQL 服务器。
回答by grex_e
Try localhost
instead of 127.0.0.1
to connect or in your connection-config
. Worked for me on a Debian Squeeze Server
尝试localhost
而不是127.0.0.1
连接或在您的connection-config
. 在 Debian Squeeze 服务器上为我工作
回答by Henry
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
回答by Yu Jiaao
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.
查看my.cnf
文件,如果包含[client]
部分,并且port
不是真正的监听端口(默认为 3306),则必须使用显式参数连接服务器-P 3306
,例如
mysql -u root -h 127.0.0.1 -p -P 3306
mysql -u 根 -h 127.0.0.1 -p -P 3306
回答by S.Roshanth
This problem may occur because your MySQL server is not installed and running. To do that start command prompt as admin and enter command:
出现此问题的原因可能是您的 MySQL 服务器未安装和运行。要以管理员身份启动命令提示符并输入命令:
"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.
如果您收到“服务已成功安装”消息,则您需要启动 MySQL 服务。为此:转到服务窗口(任务管理器 -> 服务 -> 打开服务)搜索 MySQL 并从顶部导航栏中启动它。然后,如果尝试打开 mysql.exe 它将起作用。
回答by Bunyk
In my case (remote connnection) helped turning off firewall on server.
在我的情况下(远程连接)帮助关闭服务器上的防火墙。
service iptables stop
回答by nkr1pt
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.
您需要将 mysql 配置文件(my.ini 或 my.cnf)中的 bind-address 参数更改为 127.0.0.1 或使用在那里定义的参数。
If that doesn't work you should check that the mysql service is actually running.
如果这不起作用,您应该检查 mysql 服务是否实际正在运行。
回答by KDAS
Incase you are running on a non-default port, you may try using --port=<port num>
provided --skip-networking
is not enabled.
如果您在非默认端口上运行,您可以尝试使用--port=<port num>
提供的--skip-networking
是not enabled.
回答by Mightian
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).
我也面临同样的问题。以下帮助我解决了问题,转到控制面板-> 管理工具-> 服务,在此您肯定会看到 MySQL 服务:右键单击并说开始(强制启动)。
回答by Adhie_x
I just have this problem.... running in Win7 and wamp server ... after reading this
我只是有这个问题......在Win7和wamp服务器中运行......阅读后
Found that Antivirus Firewall has caused the problem.
发现防病毒防火墙导致了问题。