简体   繁体   English

连接到外部数据库时出错 - mysqli_connect(): (HY000/2002): Connection timed out

[英]Error when connecting to external db - mysqli_connect(): (HY000/2002): Connection timed out

I moved my database to an external server because the one my webhosting provider offered is just too limited (no remote access).我将我的数据库移至外部服务器,因为我的虚拟主机提供商提供的服务器太有限(无法远程访问)。 So I set a MariaDB up on a Vultr server (CentOS 7).所以我在 Vultr 服务器(CentOS 7)上设置了 MariaDB。 everything works fine in phpmyadmin and I already imported the other db. phpmyadmin 一切正常,我已经导入了另一个数据库。 When trying to connect from my website I get this warning tho:尝试从我的网站连接时,我收到以下警告:

Warning: mysqli_connect(): (HY000/2002): Connection timed out in blabla/assets/php/config.php on line 8 ERROR: Could not connect. Connection timed out

PHP code PHP代码

define('DB_SERVER', '11.22.33.44');
define('DB_USERNAME', 'user');
define('DB_PASSWORD', 'pw');
define('DB_NAME', 'data');

$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

It worked perfectly fine with the old db so I assume Im missing someting but I can't figure it out.它与旧数据库完美配合,所以我认为我错过了一些东西,但我无法弄清楚。 I tried opening the 3306 port, tried different users, allowing all IPs but nothing works.我尝试打开3306端口,尝试不同的用户,允许所有IP但没有任何效果。

Thanks for everyone who tried to help but sadly the problem is not on my end.感谢所有试图提供帮助的人,但遗憾的是问题不在我这边。 Turned out that one.com also does not allow outgoing connections to other databases than their own.原来,一个.com 也不允许与自己以外的其他数据库的传出连接。

暂无
暂无

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

相关问题 mysqli_connect(): (HY000/2002): 主机连接超时 - mysqli_connect(): (HY000/2002): Connection timed out on hosting 警告:mysqli_connect():( HY000 / 2002):拒绝连接 - Warning: mysqli_connect(): (HY000/2002): Connection refused in CodeIgniter 消息:mysqli::real_connect():(HY000/2002):连接超时,在服务器中出现错误 - CodeIgniter Message: mysqli::real_connect(): (HY000/2002): Connection timed out giving error in server mysqli_connect() mysqli_connect(): (HY000/2002): 从其他 php 文件调用时没有此类文件或目录错误 - mysqli_connect() mysqli_connect(): (HY000/2002): No such file or directory error when calling from other php file err_connection_timed_out 和 PHP 警告:mysqli_connect():(HY000/2002):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' - err_connection_timed_out and PHP Warning: mysqli_connect():(HY000/2002):Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' 警告:mysqli_connect(): (HY000/2002): 没有这样的文件或目录 - Warning: mysqli_connect(): (HY000/2002): No such file or directory 连接被拒绝“mysqli_connect(): (HY000/2002): Connection denied in ****************************conn.php on line 6 Failed - Connection refused "mysqli_connect(): (HY000/2002): Connection refused in **************************conn.php on line 6 Failed 连接错误 - SQLSTATE[HY000] [2002] 操作超时 - Connection Error - SQLSTATE[HY000] [2002] Operation timed out mysqli_connect(): (HY000/2002): 与远程服务器的连接尝试失败 - mysqli_connect(): (HY000/2002): A connection attempt failed to the remote server mysqli_connect():(HY000 / 2002):使用ipv6地址拒绝连接 - mysqli_connect(): (HY000/2002): Connection refused using ipv6 address
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM