mysql:尝试使用远程IP连接到localhost时,连接被拒绝 [英] mysql: connection refused when trying to connect to localhost using remote IP
问题描述
当我尝试使用远程IP地址连接到本地mysql数据库时,访问被拒绝.当我尝试从外部计算机连接到同一数据库时,它可以正常工作.当我使用localhost连接到本地数据库时,它也可以正常运行.例如,如果数据库服务器的IP为1.2.3.4,则会得到以下结果:
When I try to connect to a local mysql database using it's remote ip-address I get a access denied. When I try to connect to that same database from an external machine, it works without any problems. When I connect to the local database using localhost, it works perfectly as well. E.g., if the database server has the ip 1.2.3.4 then I get the following results:
# From the db server
mysql -u username -h localhost -p #works perfectly
mysql -u username -h 127.0.0.1 -p #works perfectly
mysql -u username -h 1.2.3.4 -p #Access denied
# From any other machine
mysql -u username -h 1.2.3.4 -p #works perfectly
我该怎么做才能允许使用其远程ip地址对数据库进行本地访问?数据库服务器的操作系统是Fedora 15,MySQL版本是5.5.23.
What can I do to allow local access to my database using its remote ip-address? The OS of the database server is Fedora 15 and the MySQL version is 5.5.23.
推荐答案
我自己找到了解决问题的方法,但是我仍然不太明白为什么它不起作用:
I found the solution to my problem myself, but I still don't quite understand why it didn't work:
我在主机%和localhost上向该用户授予特权:
I granted privileges to that user on the hosts % and localhost:
# Before
+-----------------+------------+
| Host | User |
+-----------------+------------+
| % | username |
| localhost | username |
+-----------------+------------+
有了这些设置,我得到了上面显示的结果.当我向主机上的该用户授予特权时,它突然起作用了.
With these settings I got the results I showed above. When I granted privileges to that user on host it suddenly did work.
# After
+-----------------+------------+
| Host | User |
+-----------------+------------+
| % | username |
| localhost | username |
| <myIpAddress> | username |
+-----------------+------------+
显然%确实适用于远程连接,但不适用于本地连接.
Apparently % does work for remote connections, but not for local connections.
这篇关于mysql:尝试使用远程IP连接到localhost时,连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!