无法连接到远程MySQL数据库 [英] Unable to connect to remote mySQL database
问题描述
我一直在尝试下面的代码尝试连接到我主办数字海洋的远程数据库。
I've been trying the following code to attempt to connect to a remote database I'm hosting on digital ocean.
MySqlConnection myConnection = new MySqlConnection("Server = 104.236.197.146; Port = 3306; Database = BattleRoyale; Uid = root; Pwd = password");
try
{
myConnection.Open();
}
catch (Exception e)
{
MessageBox.Show( e.ToString(), "Database connection error" , MessageBoxButtons.OK, MessageBoxIcon.Error);
}
每当我attemt运行此代码,我收到以下错误:
Whenever I attemt to run this code I get the following error:
MySql.Data.MySqlClient.MySqlException(0X80004005):无法连接到任何指定的MySQL主机
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySql hosts.
我相信这个问题是被托管的数据库。我试过以下的事情:
I believe the problem is with the hosted database. I've tried the following things:
GRANT ALL PRIVILEGES ON的 的根@%IDENTIFIED BY'rootPass';
GRANT ALL PRIVILEGES ON . TO root@"%" IDENTIFIED BY 'rootPass';
我一直在试图检查是否启用了TCP / IP,但我无法通过phpMyAdmin的发现,也没有通过腻子或任何东西去。
I've been trying to check to see if TCP/IP is enabled, but I cannot find it via phpMyAdmin nor going through putty or anything.
正如你所知道的,我不知道很多关于Linux的机器,我只是试图连接到这个数据库在一个学校项目。谁知道我做了什么努力来解决这个问题。 。任何帮助,将不胜感激。
As you can tell, I don't know much about Linux machines and I'm just trying to connect to this database to work on a school project. Who knows what I've done trying to fix this issue. Any help would be greatly appreciated.
推荐答案
可能的原因包括:
- MySQL的配置为侦听的本地主机或127.0.0.1只有 - 这不会允许远程连接可言,无论是防火墙配置
- MySQL可能无法在标准端口3306,但其他端口
<李>防火墙可能被配置为不通过3306端口
通信让
最有可能是1或2。尤其是1东西你不首先想到的。
Most probably it's 1. or 2. Especially 1. is something you don't think of at first.
请注意,许多主机供应商不允许从他们自己的网络的外部访问该数据库。这就是为什么经常PhpMySQL工作,但远程连接不需要。
Please note that many hosters don't allow access to the databases from outside their own network. That's why often PhpMySQL works but remote connections don't.
这篇关于无法连接到远程MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!