【问题标题】:Query a database on a different Server查询不同服务器上的数据库
【发布时间】:2017-11-18 02:05:04
【问题描述】:

为了匿名,我们假设我的网站名为www.example.com

我需要从www.example.com 访问另一个IP 地址为46.258.254.21 的服务器。

以下配置工作正常:

define ( 'DB_HOST', 'localhost' );
define ( 'DB_USER', 'siteroot' );
define ( 'DB_PASSWORD', 'sitepwd' );
define ( 'DB_DB', 'my_db' );

以下配置无效:

define ( 'DB_HOST', '46.258.254.21' );
define ( 'DB_USER', 'ifd' );
define ( 'DB_PASSWORD', 'pwd' );
define ( 'DB_DB', 'my_db1' );

它抛出了一个Could not connect to MySQL server was not found on this server. 异常。

什么可能阻止我连接到46.258.254.21

【问题讨论】:

  • 您的数据库是否在端口号上?
  • 这是安装xampp的Linux服务器,如何查看端口?
  • 请看下面的答案。它应该可以帮助你。

标签: php mysql exception database-connection


【解决方案1】:

检查事项:

  • 您的 MySQL 实例的端口号可以在 mysql 配置文件中找到:my.cnf。通常是 3306。
  • 如果您从远程计算机访问数据库服务器,则需要在防火墙上打开此端口。否则会被屏蔽。您可能希望将端口限制为 Web 服务器的 IP 地址,如 in this answer 所述。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-02-24
    • 2014-01-03
    • 1970-01-01
    • 2021-01-29
    • 2010-09-06
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    相关资源
    最近更新 更多