错误 2003 (HY000):无法连接到“主机名”上的 MySQL 服务器 (111)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18083045/
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 'hostname' (111)
提问by ASettouf
Thanks in advance for your help.
在此先感谢您的帮助。
I am facing an issue with mysql server which is the title of this topic, by using the command:
通过使用以下命令,我正面临 mysql 服务器的问题,这是本主题的标题:
mysql -u myuser -pmypass -h `hostname` db_name
I get the error
我收到错误
ERROR 2003 (HY000): Can't connect to MySQL server on 'hostname' (111)
So I checked the my.cnffile and I have no lines with "bind address" and "skip-networking" although I tried adding them and restarting which did not change anything.
所以我检查了my.cnf文件,但我没有包含“绑定地址”和“跳过网络”的行,尽管我尝试添加它们并重新启动,但没有任何改变。
Besides that there is no error in the sql logs, and we can (with HeidiSQL) connect to the server remotely knowing that the user is myuser"@"%
. Mysql listens on the port 3306, so it's ok there
除此之外,sql 日志中没有错误,我们可以(使用 HeidiSQL)远程连接到服务器,知道用户是myuser"@"%
. Mysql监听3306端口,所以没问题
Also, users created with with @'localhost', works fine with the command line (without the -h option).
此外,使用@'localhost' 创建的用户可以在命令行中正常工作(不带 -h 选项)。
What is more intriguing is that other servers that look exactly the same work both locally and remotely with the first command...
更有趣的是,其他看起来完全相同的服务器使用第一个命令在本地和远程工作......
The server runs with CentOS 6.2
服务器运行 CentOS 6.2
So if anyone has an idea on this matter I would be glad to hear it
因此,如果有人对此事有任何想法,我会很高兴听到
P.S : It's my first time posting here, so if there are formatting issues, please forgive me
PS:第一次发帖,如有格式问题请见谅
回答by MiPnamic
Simply check your my.cnf and change from
只需检查您的 my.cnf 并从
bind-address = 0.0.0.0
to
到
bind-address = 127.0.0.1
if you don't have that parameter just add it.
如果您没有该参数,只需添加它。
Binding to the 0.0.0.0 let your mysql being available on every IP configured cause you can't bind just on two or three IP on the server, the config can be: localhost or everything.
绑定到 0.0.0.0 让你的 mysql 在每个配置的 IP 上都可用,因为你不能只在服务器上的两个或三个 IP 上绑定,配置可以是:localhost 或所有东西。
Then check your /etc/hosts file and be sure that the line
然后检查您的 /etc/hosts 文件并确保该行
127.0.0.1 localhost
contains also your server hostname, as example: my hostname is "db01", my /etc/hosts is
还包含您的服务器主机名,例如:我的主机名是“db01”,我的 /etc/hosts 是
127.0.0.1 localhost db01
Keep in mind that after the install process via yum (I don't know if CentOS do this automagically for you, I just know that Gentoo does not) you have to execute mysql_install_db and then configure the password for the root user, be absolutely sure that you'd set up a password for:
请记住,在通过 yum 安装过程之后(我不知道 CentOS 是否会自动为您执行此操作,我只知道 Gentoo 没有)您必须执行 mysql_install_db 然后为 root 用户配置密码,请绝对确定您将为以下各项设置密码:
'root'@'localhost'
'root'@'hostname'
'root'@'127.0.0.1'
'root'@'%'
(for security issue be also sure to remove from mysql.user those entry with user='')
(为了安全问题,也一定要从 mysql.user 中删除那些带有 user='' 的条目)
hope this helps
希望这可以帮助
回答by nucc1
Belated response, but I believe that error message means that the server you are trying to connect to is not listening on that interface.
迟来的响应,但我相信该错误消息意味着您尝试连接的服务器未在该接口上侦听。
If you change the config to:
如果将配置更改为:
bind-address = 127.0.0.1
bind-address = 127.0.0.1
as suggested above, what you are doing is configuring the server to reject all connections except those from localhost (itself).
如上所述,您正在做的是配置服务器以拒绝除来自本地主机(本身)的连接之外的所有连接。
bind-address = 0.0.0.0
bind-address = 0.0.0.0
is in most cases sufficient, and makes mysql listen on all interfaces on the system, which makes it accessible via all the addresses that the host is accessible at.
在大多数情况下就足够了,并使 mysql 侦听系统上的所有接口,这使得它可以通过主机可访问的所有地址进行访问。
回答by Dinesh-SriLanka
Enable port on firewall and try...
在防火墙上启用端口并尝试...
in terminal,
execute commands as root
.
在终端中,以root
.
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
回答by saneryee
There is a reason I met that You MySQL server's IP address conflictwith other server in your local network.
我遇到的原因是您的 MySQL 服务器的IP 地址与本地网络中的其他服务器冲突。