[英]Unable to connect to remote MySQL Server
I have a server attempting to connect to a MySQL database hosted outside of the local network.我有一台服务器试图连接到本地网络之外托管的 MySQL 数据库。 I am attempting to use a public IP address to connect to it.我正在尝试使用公共 IP 地址连接到它。
Testing the connection in the command line gives me this error:在命令行中测试连接给了我这个错误:
ERROR 2003 (HY000): Can't connect to MySQL server on '[ip_address]' (146)
PDO gives me the same error. PDO 给了我同样的错误。 In any case, the connection works fine locally and within the same network, which is what boggles my mind.无论如何,连接在本地和同一网络内都可以正常工作,这让我感到困惑。
The MySQL server has had its bind-address modified so it accepts remote connections. MySQL 服务器已修改其绑定地址,因此它接受远程连接。 The MySQL server also has a user with the proper privileges set. MySQL 服务器还有一个具有适当权限集的用户。 But in any case, it looks as though I can't even start the connection in the first place.但无论如何,看起来我什至无法首先启动连接。
Is there a my.cnf value I need to add to let MySQL accept requests from outside the local network?是否需要添加 my.cnf 值才能让 MySQL 接受来自本地网络外部的请求?
Thanks.谢谢。
Things to check:检查事项:
my.cnf
file configured to allow connections from anything other than localhost
127.0.0.1
IPs - although you'd more likely get a access denied response, than a cannot connect. my.cnf
文件是否配置为允许来自除localhost
127.0.0.1
IP 以外的任何内容的连接 - 尽管您更有可能得到访问被拒绝的响应,而不是无法连接。grant privileges to the user from that particular host.从该特定主机向用户授予权限。 or to access it from any host use % (ie wild card) as host.或从任何主机使用 %(即通配符)作为主机访问它。
It definitely sounds like the client isn't able to connect.听起来肯定是客户端无法连接。 This page has some suggestions on how to narrow down the problem:这个页面有一些关于如何缩小问题范围的建议:
http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html
What happens if you try to telnet to port 3306 on the server?如果您尝试 telnet 到服务器上的 3306 端口会发生什么? You should get a prompt from MySQL.你应该从 MySQL 得到一个提示。
Grant the privileges for all users using the command使用命令为所有用户授予权限
GRANT ALL PRIVILEGES ON .授予所有特权。 TO 'root'@'localhost' IDENTIFIED BY 'root' WITH GRANT OPTION; TO 'root'@'localhost' 由 'root' 标识,并带有 GRANT 选项; GRANT ALL PRIVILEGES ON .授予所有特权。 TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; TO 'root'@'%' 由 'root' 标识,带有 GRANT 选项; FLUSH PRIVILEGES;同花顺特权;
Now go to your "my.cnf" file.现在转到您的“my.cnf”文件。 For ubuntu use (sudo find / -type f -name "my.cnf")对于 ubuntu 使用(sudo find / -type f -name "my.cnf")
comment out the line "bind-address = 127.0.0.1"注释掉“bind-address = 127.0.0.1”这一行
restart mysql using For ubuntu use "sudo service mysql restart"使用 ubuntu 重新启动 mysql 使用“sudo service mysql restart”
I had the same issue and most of the solutions given are:我遇到了同样的问题,给出的大多数解决方案是:
But in my case, the database was hosted on a remote server and the router required port forwarding.但就我而言,数据库托管在远程服务器上,路由器需要端口转发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.