简体   繁体   English

无法从 AWS EC2 访问 Godaddy 托管的 MySQL 服务器

[英]Failing to access a Godaddy hosted MySQL server from AWS EC2

I have a MySQL server hosted in my Godaddy server.我在我的 Godaddy 服务器中托管了一个 MySQL 服务器。 I want to access that database from my EC2 instance.我想从我的 EC2 实例访问该数据库。 However, I am unable to do so.但是,我无法这样做。 I have added the public IP of my EC2 instance to the remote MySQL access hosts.我已将我的 EC2 实例的公共 IP 添加到远程 MySQL 访问主机。

Things I have tried:我尝试过的事情:

  1. By using my Godaddy hosted website name as my server name.通过使用我的 Godaddy 托管网站名称作为我的服务器名称。
  2. Using my Godaddy hosted website IP address as my server name.使用我的 Godaddy 托管网站 IP 地址作为我的服务器名称。

Every time I try to connect, It gives me the error:每次我尝试连接时,它都会给我错误:

Connection failed: Unknown MySQL server host '<hostname>:3306' (11)连接失败:未知 MySQL 服务器主机 '<hostname>:3306' (11)

Script I used:我使用的脚本:

<?php
$servername = "<hostname>:3306";
$username = "<username>";
$password = "<password>";
$dbname = "<dbname>";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

PS: I can successfully connect my MySQL workbench and a locally hosted server to my Godaddy database. PS:我可以成功地将我的 MySQL 工作台和本地托管的服务器连接到我的 Godaddy 数据库。

Try removing :3306 from $servername尝试从$servername删除:3306

Make sure the arguments are correct.确保参数正确。 mysqli() needs port as separate argument as described here mysqli()需要端口作为单独的参数如所描述的在这里

According to godaddy you need to enable Allow Direct Database Access for remotely connections.根据godaddy,您需要为远程连接启用允许直接数据库访问。

Link here! 链接在这里!

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

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