连接到外部 mysql 数据库时出现问题

发布于 2024-09-26 18:19:36 字数 288 浏览 1 评论 0原文

我的问题是,当我尝试从我们的服务器连接到另一个外部服务器时,此命令会产生错误:

mysql -h db.hostname.com -u username -pP@ssword database_name

这是错误:

错误 1044 (42000): 用户 'username'@'%' 访问数据库 'database_name'

I 被拒绝已经要求外部服务器管理员在他们的防火墙中添加我们的 IP,但无济于事。

这是否与向“用户名”授予权限有关

My problem is this command produces an error when I tried to connect from our server to another external server :

mysql -h db.hostname.com -u username -pP@ssword database_name

And this is the error :

ERROR 1044 (42000): Access denied for user 'username'@'%' to database 'database_name'

I already asked the external server admin to add our IP in their firewall but to no avail..

Has this something to do with GRANTing privileges to the 'username'

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

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

发布评论

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

评论(2

那片花海 2024-10-03 18:19:36

这不是防火墙的问题,因为 MySQL 拒绝连接。正如您怀疑的那样,这是授予用户的权限的问题。您需要在 mysql 服务器上执行此操作(如果您不想向数据库授予所有权限,则可能需要稍微调整一下):

GRANT ALL ON database_name.* TO 'username'@'%' IDENTIFIED BY 'P@ssword';

另请注意,如果您始终从特定主机/IP 连接,则更好想法指定主机/IP,而不是使用通配符 %,这将允许来自任何地方的连接。

It's not a problem with firewall, since MySQL is denying the connection. As you suspect, it is a problem with the privileges granted for the user. You need to execute this on the mysql server (you might need to tweak this a bit if you don't want to grant all privileges to the db):

GRANT ALL ON database_name.* TO 'username'@'%' IDENTIFIED BY 'P@ssword';

Also note that if you always connect from a specific host/ip, it's a better idea to specify that host/ip, instead of using a wildcard %, which would allow connections from anywhere.

念﹏祤嫣 2024-10-03 18:19:36

听起来密码错误,或者您尝试使用的用户名不允许从您的计算机的 IP 地址进行连接。

如您所知,远程站点的 mysql 管理员可以指定允许使用任何给定用户帐户连接的 IP。请记住,在到达外部数据库之前,您计算机的 IP 地址可能会通过公司端的各种路由器和防火墙。因此,您的 IP 对您来说可能与外部数据库中不同。
在这种情况下,如果外部数据库管理员将您的 IP 添加到“允许”列表中也无济于事,他们应该添加“外部”IP 地址。

确定这是否适用于您的最简单方法如下:
访问 www.whatismyip.com 并记下屏幕上的 IP 地址。这是从“外部世界”看到的您的 IP。该 IP 很可能实际上是您公司网络内的防火墙或路由器的外部 IP,而不是您计算机的 IP。

接下来,(假设您使用的是 Windows)转到“开始”>“跑步。输入cmd并按回车键。键入 ipconfig 并按 Enter 键。您现在可以看到您的本地 IP 地址。

如果这两个 IP 不匹配,请告诉远程管理员将您的外部 IP 添加到“允许”列表中。

另外,一旦您投入生产并将代码移至另一台服务器,IP 的乐趣就会再次开始。你不妨立即解决这个问题

It sounds like the password is wrong, or that the username you are trying to use is not allowed to connect from your computer's IP address.

as you know, the mysql administrator at the remote site can specify which IP's are allowed to connect using any given user account. Bear in mind that your computer's IP address may be routed through all kinds of routers and firewalls on your company's end before you reach the external database. As a result, your IP may appear different to you than to the external database.
In that case, it doesn't help if the external database admin adds YOUR IP to the 'allowed' list, they should add the 'outside world' IP address instead.

The easiest way to find out if this applies to you, is as follows:
visit www.whatismyip.com and write down the IP address on screen. This is your IP as seen from the 'outside world'. It is very likely that this IP is actually the outside IP of a firewall or router within your company's network, and not your computer's IP at all.

Next, (assuming you're on Windows) go to Start > run. Type cmd and hit enter. Type ipconfig and hit enter. You can now see your local IP address.

If these two IP's don't match, tell the remote admin to add your outside world IP to the 'allowed' list as well.

also - once you go to production, and move your code to another server, the IP fun starts again. You might as well fix this right away

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