2003 - 无法连接到“本地主机”上的 MySQL 服务器 (10038)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25842341/
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
2003 - Can't connect to MySQL server on 'localhost' (10038)
提问by Y.L.
I installed mysql server in my ubuntu virtual machine, then I use Navaicat for Mysql to connet mysql, but failed.
Navicat for Mysql is installed on Windows 7,
Navicat version is 11.0.10, enterprise edition
mysql is installed in my virtual machine, the system is Ubuntu 12,
when I connect the mysql server, it returns:
我在我的ubuntu虚拟机中安装了mysql服务器,然后我使用Navaicat for Mysql连接mysql,但是失败了。Navicat for Mysql安装在Windows 7上,Navicat版本是11.0.10,我的虚拟机安装的是企业版mysql,系统是Ubuntu 12,当我连接mysql服务器时,返回:
my navicat connection configuration:
我的 navicat 连接配置:
I tried several methods, including use the command: grant all privileges on .to 'root'@'%' identifed by 'passwd' with grant option
and I shutdown the firewall of ubuntu using: ufw disable
and I hava also shutdown the firewall of windows 7,
the state of port 3306 of the ubuntu server is:
我尝试了几种方法,包括使用命令:grant all privileges on . 到 'root'@'%' 由 'passwd' 与授权选项标识,我使用以下命令关闭了 ubuntu 的防火墙:ufw disable 并且我还关闭了 Windows 7 的防火墙,ubuntu 服务器的端口 3306 的状态是:
the iptable rules is like this:
iptable 规则是这样的:
the mysql.user table is like this:
mysql.user 表是这样的:
but still, the navicat gives me the error: 2003 - can't connect to mysql server on 'localhost' (10038)
但是,navicat 仍然给我错误:2003 - 无法连接到 'localhost' (10038) 上的 mysql 服务器
anyone can help me? thank you!
任何人都可以帮助我吗?谢谢你!
回答by Y.L.
I solved this problem. In my /etc/mysql/my.cnf, the command bind the locahost address like this: bind-address=127.0.0.1, just add a # before it. and now I can connect to the mysql server smoothly.
我解决了这个问题。在我的/etc/mysql/my.cnf中,命令绑定locahost地址是这样的:bind-address=127.0.0.1,在它前面加一个#就可以了。现在我可以顺利连接到mysql服务器了。
回答by Giga Kokaia
Try add Port Forwarding Rule
in viritual machine configuration, Settings > Network > Adapter1 > Advanced > "Port Forwarding"
尝试添加Port Forwarding Rule
虚拟机配置,Settings > Network > Adapter1 > Advanced > "Port Forwarding"
回答by zjien
Find the
my.cnf
file in path/etc/mysql/
Find
bind-address = 127.0.0.1
and comment it out like so:#bind-address = 127.0.0.1
Restart MySQL
Now we have a problem with not being allowed to connect to this MySQL server, thus we need to continue
Use the following MySQL command:
找到
my.cnf
路径中的文件/etc/mysql/
bind-address = 127.0.0.1
像这样找到并注释掉它:#bind-address = 127.0.0.1
重启 MySQL
现在我们遇到了不允许连接到这个 MySQL 服务器的问题,因此我们需要继续
使用以下 MySQL 命令:
grant all PRIVILEGES on database_name.* to user_name@'%' identified by 'user_password';
Check the
user_privileges
table in theinformation_schema
database and make sure thatuser_name
has been added in the table.Login to remote MySQL from local using the
user_name
检查数据库中的
user_privileges
表information_schema
并确保user_name
已将其添加到表中。使用以下命令从本地登录到远程 MySQL
user_name