将 php-sql 连接失败缩小到服务器设置?
我正在尝试从服务器 B 连接到服务器 A 上的 MYSQL 数据库。与我们合作的托管公司拥有服务器 A 和服务器 B。这是我第一次尝试外部数据库连接。
我编写了以下 PHP 代码来尝试从服务器 B 连接到服务器 A 上的 MYSQL 数据库。该代码看起来像我在 Google 上搜索到的有关连接到外部 MYSQL 数据库的大多数其他代码。
$IPAddress_O_fServer_A = 'XXX.XX.XX.XXX';
$Server_A_DB_Pass = 'P-WORD';
$Server_A_DB_User = 'U-NAME';
$con = mysql_connect($IPAddress_Of_Server_A, $Server_A_DB_User, $Server_A_DB_Pass);
现在,当此代码在服务器 B 上执行时,我收到此错误:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'XXX.XX.XX.XXX' (4) in /var/www/web12/web/dev/front-end.php on line 10
Could not connect: Can't connect to MySQL server on XXX.XX.XX.XXX' (4)
...其中第 10 行是 mysql_connect() 调用。
有人看到这段代码有什么问题吗? 如果连接不起作用,是否可以肯定地说服务器外部连接权限或其他一些设置一定存在问题?
谢谢!
I am trying to connect to a MYSQL database on server A from server B. The hosting company that we are working with, owns both server A and server B. This is my first attempt at an external DB connection.
I have written the following PHP code to try to connect to the MYSQL database on server A from server B. The code looks like most other code I have Googled in regards to connecting to external MYSQL databases..
$IPAddress_O_fServer_A = 'XXX.XX.XX.XXX';
$Server_A_DB_Pass = 'P-WORD';
$Server_A_DB_User = 'U-NAME';
$con = mysql_connect($IPAddress_Of_Server_A, $Server_A_DB_User, $Server_A_DB_Pass);
Now when this code executes on Server B, I get this error:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'XXX.XX.XX.XXX' (4) in /var/www/web12/web/dev/front-end.php on line 10
Could not connect: Can't connect to MySQL server on XXX.XX.XX.XXX' (4)
...where line 10 is the mysql_connect() call.
Does anyone see anything wrong with this code?
If the connection is not working would it be safe to say that there must be an issue with either the servers external connection permissions or some other settings?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先我会看看 此并确保您的系统配置为允许远程访问。
其次,用户名“U-NAME”实际上将是“U-NAME@localhost”,并且将具有这样的权限设置。例如,考虑以下 GRANT 语句。
用户名“U-NAME”有权从数据库 foo、表 bar 中选择条目,但只能进行 localhost 访问。为了允许远程,您必须授予类似于以下内容的权限。
First off I'd look at this and make sure that you're system is configured to allow remote access.
Secondly the user name "U-NAME" will actually be "U-NAME@localhost" and will have permissions set up as such. For example consider the following GRANT statement.
The user name "U-NAME" has permission to select entries from the database foo, table bar, but it is exclusively localhost access. In order to allow remote you'd have to grant permissions similarly to the following.