连接到不同服务器上的 MySQL

发布于 2024-09-24 11:07:28 字数 703 浏览 8 评论 0原文

我有两台服务器(虚拟机 - 我可以远程连接到它们) - 服务器 1 和服务器 2。

在服务器 1 上我保留我的网页,在服务器 2 上我保留数据库。

我目前正在尝试从服务器 1 连接到服务器 2 上的数据库。

这是我的 php 代码:

<?php
            $dbhost = 'xxx.xx.xx.xx:xxxx';
            $dbuser = 'xxxxxx';
            $dbpass = 'xxxxxx';

            $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql' . mysql_error());


            $dbname = 'database';
            mysql_select_db($dbname);
?>

这是我尝试连接时收到的错误消息:

Access denied for user 'xxxxxx'@'server1' (using password: YES)

我发现它有点令人费解,它说 @server1 考虑到我是尝试连接到服务器 2。任何人都可以提供任何见解吗?

谢谢

PS:它们都在 Windows 2008 上

I have two servers (virtual machines - I can remotely connect to these) - server 1, and server 2.

On server 1 I keep my webpages, and on server 2, I keep the databases.

I am currently trying to connect to a database on server 2 from server 1.

Here is my php code:

<?php
            $dbhost = 'xxx.xx.xx.xx:xxxx';
            $dbuser = 'xxxxxx';
            $dbpass = 'xxxxxx';

            $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql' . mysql_error());


            $dbname = 'database';
            mysql_select_db($dbname);
?>

This is the error message I get when I try to connect:

Access denied for user 'xxxxxx'@'server1' (using password: YES)

I found it a bit puzzling that it says @server1 considering I'm trying to connect to server 2. Can anyone offer any insights?

Thanks

PS: They're both on windows 2008

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

高冷爸爸 2024-10-01 11:07:28

MySQL 在确定是否授予访问权限时会考虑连接客户端的主机名。可以允许给定的用户名从托管数据库的同一台计算机(即本地主机)登录,但在从远程系统使用时不允许连接。

在您的情况下,听起来用户“xxxxxx”无权从“server1”连接。您可以授予用户“xxxxxx”从所有主机(“%”)登录的权限。但是,将您的该帐户的登录权限限制到所需的特定主机(“server1”)或主机范围(“%.mydomain.com”或“144.155.166.0/255.255.255.0”)会更安全。被使用。

有关 MySql 身份验证过程这方面的更多信息,请参阅 http: //dev.mysql.com/doc/refman/5.0/en/connection-access.html

MySQL factors in the host name of the connecting client when determining whether or not to grant access. A given username may be allowed to log in from the same machine that is hosting the database (i.e. localhost) but not allowed to connect when used from a remote system.

In your case, it sounds like user 'xxxxxx' is not authorized to connect from 'server1'. You could grant user 'xxxxxx' login rights from all hosts ('%'). However, it would be more secure to limit your that account's login rights to the specific host ('server1') or range of hosts ('%.mydomain.com' or '144.155.166.0/255.255.255.0') from which it needs to be used.

For more information on this aspect of MySql's authentication process, see http://dev.mysql.com/doc/refman/5.0/en/connection-access.html.

开始看清了 2024-10-01 11:07:28

“Access Denied for user 'xxxxxx'@'server1'”表示 server1 无权访问 server2。您需要在 server2 上添加新用户,该用户可以从 server1 连接(主机名:server1);

"Access denied for user 'xxxxxx'@'server1'" means that server1 don't have access to server2. You need to add new user on server2 which can connect from server1 (hostname: server1);

网名女生简单气质 2024-10-01 11:07:28

您需要授予该计算机的权限

此处查看

You need to give rights for that machine

Check it here

桃扇骨 2024-10-01 11:07:28

删除该用户并使用“xxxxxx”@“%”创建一个新用户。在两台服务器上执行此操作。
@'%' 表示用户可以从任何地方连接。

Remove this user and create a new one with 'xxxxxx'@'%'. Do this on both servers.
@'%' indicates that the user can connect from anywhere.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文