MySQL 权限被本地拒绝但可以远程连接
我正在尝试通过以下命令连接到远程服务器上的 mysql 数据库(通过 ssh):
mysql -u me -h mydomain.com -p
但它失败并出现错误 1045 (28000): Access returned for user.. error
While
mysql -u me -h localhost -p
Works
Now 这不仅仅是因为我有不设置权限,因为该数据库的权限是为me用户设置的%或任何主机。
我可以使用同一用户从本地计算机正确连接到服务器,这一事实证明了这一点。即从本地计算机运行以下命令有效:
mysql -u me -h mydomain.com -p
那么我的问题为什么会发生这种情况以及如何修复它?当我使用域名而不是 localhost 时,为什么无法从我的服务器连接到我的 mysql 服务器,即使权限设置为接受来自任何主机的连接。
I am trying to connect to my mysql database on a remote server (via ssh) through the command:
mysql -u me -h mydomain.com -p
But it fails with a ERROR 1045 (28000): Access denied for user.. error
While
mysql -u me -h localhost -p
Works
Now this isn't just because I have not setup permissions, because the permissions to this database are set for % or any host for the me user.
This is proved by the fact that I can connect correctly from my local machine to the server, using the same user. i.e. running the following command from my local machine works:
mysql -u me -h mydomain.com -p
So my question why does this happen and how can I fix it? Why can I not connect to my mysql server from my server when I use the domain name instead of localhost, even though the permissions are setup to accept connections from any host.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况是因为 MySQL 处理权限授予的方式。
当您从远程主机(或通过外部 IP 从本地主机)连接时,它将匹配
me@%
条目(如果没有针对该条目的特定授权)您正在使用的特定主机!)。但是,当您通过环回接口(“localhost”IP)或套接字连接时,它将使用me@localhost
授权。所以你必须有两个GRANT PRIVILEGES
;一个用于me@localhost
,另一个用于me@%
。This happens because of the way MySQL handles permission grants.
When you connect from a remote host (or from the local host via an external IP), it will match the
me@%
entry (if there is no specific grant for the particular host you're using!). But when you connect via the loopback interface (the "localhost" IP) or a socket, it will use theme@localhost
grant. So you must have twoGRANT PRIVILEGES
; one forme@localhost
and one forme@%
.