如何连接到在虚拟机上运行的 MySQL 服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16954395/
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
How to connect to a MySQL server running on a Virtual Machine
提问by Mono Jamoon
I have a MySQL Server 5.5.32 running on Ubuntu 12.04. Ubuntu is being run on VM. Host platform is Windows 7. How can I connect with the Ubuntu's MySQL from Windows?
我有一个在 Ubuntu 12.04 上运行的 MySQL Server 5.5.32。Ubuntu 正在 VM 上运行。主机平台是Windows 7。如何从Windows 连接Ubuntu 的MySQL?
I have done the following so far:
到目前为止,我已经完成了以下工作:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Running a show grant for root;
displays this:
运行 ashow grant for root;
显示:
+-------------------------------------------------------------+
| Grants for root@% |
+-------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION |
+-------------------------------------------------------------+
But when I try to connect to this server from SQLYog running on Windows, I get an error Error 2003 Cannot connect to mysql server on '192.168.xxx.xxx'
.
但是,当我尝试从 Windows 上运行的 SQLYog 连接到此服务器时,出现错误Error 2003 Cannot connect to mysql server on '192.168.xxx.xxx'
。
The IP being feed to SQLYog, I got it from ifconfig
. Supplied the inet addr.
提供给 SQLYog 的 IP,我是从ifconfig
. 提供 inet 地址。
inet addr:192.168.226.xxx Bcast:192.168.226.yyy
Is the address being used is incorrect or are these grant issues? Please advice.
使用的地址是不正确还是这些授权问题?请指教。
回答by Arkadiusz 'flies' Rzadkowolski
You problem is that (probably) your mysql is bind to 127.0.0.1
instead of 0.0.0.0
.
您的问题是(可能)您的 mysql 绑定到127.0.0.1
而不是0.0.0.0
.
You should change bind in /etc/mysql/my.cnf
to 0.0.0.0
您应该将绑定更改/etc/mysql/my.cnf
为0.0.0.0
bind-address = 0.0.0.0
bind-address = 0.0.0.0
And then restart mysql of course.
然后当然是重启mysql。
回答by Kamiel Ahmadpour
In newer versions of MySQL, instead of skip-networking the default is now to listen only on localhost bind-address = 127.0.0.1
在较新版本的 MySQL 中,现在的默认设置不是跳过网络,而是仅在 localhost bind-address = 127.0.0.1 上侦听
So you need to add your machine IP to here or simply comment it out if you are not worry about security concerns.
因此,如果您不担心安全问题,您需要将您的机器 IP 添加到此处或简单地将其注释掉。
回答by Sathish D
The error message Error No. 2003: Can't connect to MySQL server on 'localhost' (or some other host)
错误信息 Error No. 2003: Can't connect to MySQL server on 'localhost' (or some other host)
simply means that connection is not possible for one of the following (or similar) reasons:
仅表示由于以下(或类似)原因之一无法连接:
There is no MySQL server running at the specified host
Connection to the MySQL server is not allowed using TCP-IP. Check the 'skip-networking' setting in the MySQL configuration file (my.ini on Windows, my.cnf on Unix/Linux). It shall be commented out like '#skip-networking'. If it is not commented out, then do it and restart the MySQL server for the change to take effect. SQLyog needs to connect using TCP-IP.
Some networking issue prevents connection. It could be a network malconfiguration or a firewall issue. We have experienced sometimes that some firewalls is blocking TCP-IP connections even if it claims to be disabled. Most often it will help to uninstall and reinstall the firewall.
When trying to connect to a MySQL server at an ISP this error message often indicates that direct connection to MySQL has been blocked. You must then use HTTP-tunneling or SSH-tunneling to connect.
指定主机上没有运行 MySQL 服务器
不允许使用 TCP-IP 连接到 MySQL 服务器。检查 MySQL 配置文件(Windows 上的 my.ini,Unix/Linux 上的 my.cnf)中的“skip-networking”设置。它应该像'#skip-networking'一样被注释掉。如果没有注释掉,那么做并重新启动MySQL服务器以使更改生效。SQLyog 需要使用 TCP-IP 进行连接。
一些网络问题阻止连接。这可能是网络配置错误或防火墙问题。我们有时会遇到一些防火墙会阻止 TCP-IP 连接,即使它声称已禁用。大多数情况下,它有助于卸载并重新安装防火墙。
当尝试连接到 ISP 处的 MySQL 服务器时,此错误消息通常表明与 MySQL 的直接连接已被阻止。然后,您必须使用 HTTP 隧道或 SSH 隧道进行连接。
回答by Prabhakar Manthena
I think the problem is with the Network Adapter settingsin your VM settings
我认为问题出在 VM 设置中的网络适配器设置
Do like this in your VM settings.
在您的 VM 设置中执行此操作。
VM Settings -> Network Adapter Settings -> Select Bridged
VM 设置 -> 网络适配器设置 -> 选择桥接
The VM will connect to the physical network when the network connection is on bridged mode.
当网络连接处于桥接模式时,VM 将连接到物理网络。
Try to ping the VM host in your windows machine after changing the network connection to bridged.
将网络连接更改为bridged后,尝试 ping Windows 计算机中的 VM 主机。
If the VM is pinging in your windows machine then it will work.
如果 VM 在您的 Windows 机器上 ping,那么它将起作用。
回答by Prabhakar Manthena
Error No. 2003: Can't connect to MySQL server on '192.168.x.x'
错误号 2003:无法连接到“192.168.xx”上的 MySQL 服务器
simply means that connection is not possible for one of the following (or similar) reasons:
仅表示由于以下(或类似)原因之一无法连接:
There is no MySQL server running at the specified host
Connection to the MySQL server is not allowed using TCP-IP. Check the 'skip-networking' setting in the MySQL configuration file (my.ini on Windows, my.cnf on Unix/Linux). It shall be commented out like '#skip-networking'. If it is not commented out, then do it and restart the MySQL server for the change to take effect. SQLyog needs to connect using TCP-IP.
Make sure that you are able to connect to MySQL port using telnet
C:\telnet hostname/IP_address port
指定主机上没有运行 MySQL 服务器
不允许使用 TCP-IP 连接到 MySQL 服务器。检查 MySQL 配置文件(Windows 上的 my.ini,Unix/Linux 上的 my.cnf)中的“skip-networking”设置。它应该像'#skip-networking'一样被注释掉。如果没有注释掉,那么做并重新启动MySQL服务器以使更改生效。SQLyog 需要使用 TCP-IP 进行连接。
确保您能够使用 telnet 连接到 MySQL 端口
C:\telnet 主机名/IP_address 端口