简体   繁体   English

无法连接到安装在另一个虚拟机上或通过网络的 MySQL

[英]Unable to connect to MySQL installed on another virtual machine or over network

I have several vms instances running in my vm player.我的 vm 播放器中运行了几个 vms 实例。 Several of them are cent-OS acting as HTTP servers.其中有几个是 cent-OS,充当 HTTP 服务器。 The HTTP server is/are accessible over network. HTTP 服务器可通过网络访问。 The HTTP server is on nginx. HTTP 服务器位于 nginx 上。

Then I have a vm running on cent-OS having MySQL installed.然后我有一个在安装了 MySQL 的cent-OS 上运行的虚拟机。 And another vm instance running MS Server 2019 having MySQL Installed.另一个运行 MS Server 2019 的 vm 实例安装了 MySQL。 Am using MySQL 8.0.18 on both these machines.我在这两台机器上都使用 MySQL 8.0.18。

All these machines are on same sub-net and gateway.所有这些机器都在同一个子网和网关上。 for example the IP of one of my vm having HTTP server is 192.168.0.133.例如,我的一台具有 HTTP 服务器的虚拟机的 IP 是 192.168.0.133。 And the machines with cent-OS having MySQL Server installed is having IP 192.168.0.140 and machine with MS Server 2019 having MySQL server is having IP 192.168.0.141. And the machines with cent-OS having MySQL Server installed is having IP 192.168.0.140 and machine with MS Server 2019 having MySQL server is having IP 192.168.0.141.

Now the issue is am unable to access any of these MySQL servers from the network(LAN) or in other words am unable to access the MySQL server running on either.140 or.141 from the machine.133 meanwhile am able to access the HTTP server across the network.现在的问题是无法从网络(LAN)访问这些 MySQL 服务器中的任何一个,或者换句话说,我无法从机器访问在 140 或 141 上运行的 MySQL 服务器。133 同时能够访问 Z293C666EA246FF998988A66跨网络的服务器。

But if I running MySQL server on the same machine having HTTP server.但是,如果我在具有 HTTP 服务器的同一台机器上运行 MySQL 服务器。 There occurs no problem whether I use 127.0.0.1 or localhost in my db host configuration无论我在我的数据库主机配置中使用 127.0.0.1 还是 localhost 都没有问题

My application is based on a PHP framework known as laravel.我的应用程序基于称为 laravel 的 PHP 框架。

I have disabled firewall from both the above machines.我已禁用上述两台机器的防火墙。 The port 3306 is open on both machines.两台机器上的 3306 端口都是开放的。 Am able to ping all machines with each other.我能够相互ping通所有机器。

I had tried things like:我试过这样的事情:

skip-networking(commenting out this one or just deleting), bind-address(IP of the machine running MYSQL server), grant privileges on an ip or from any IP to users/user, flush privileges跳过网络(注释掉这个或只是删除),绑定地址(运行 MYSQL 服务器的机器的 IP),授予 ip 或任何 IP 上的权限

Even modified iptables.甚至修改了iptables。

Am entering db host as the IP of the machine where MySQL is running.我正在输入 db host 作为 MySQL 正在运行的机器的 IP。 The error am getting is SQLSTATE[HY000] [2002] Connection refused我得到的错误是 SQLSTATE[HY000] [2002] Connection denied

You've nearly done it all right.你几乎已经做好了。 Setting bind-address to the server's IP however means that you must connect via SSH.但是,将绑定地址设置为服务器的 IP 意味着您必须通过 SSH 进行连接。

Change the IP to 0.0.0.0 and restart MySQL, and hopefully that should be you all set.将 IP 更改为0.0.0.0并重新启动 MySQL,希望这一切都完成了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM