问题描述
在Windows XP上运行的MySQL 5.1.31.
MySQL 5.1.31 running on Windows XP.
从本地 MySQL服务器(192.168.233.142),我可以以root用户身份进行如下连接:
From the local MySQL server (192.168.233.142) I can connect as root as follows:
>mysql --host=192.168.233.142 --user=root --password=redacted
从远程计算机(192.168.233.163),我可以看到mysql端口已打开:
From a remote machine (192.168.233.163), I can see that the mysql port is open:
# telnet 192.168.233.142 3306
Trying 192.168.233.142...
Connected to 192.168.233.142 (192.168.233.142).
但是当尝试从远程机器连接到mysql时,我收到:
But when trying to connect to mysql from the remote machine, I receive:
# mysql --host=192.168.233.142 --user=root --password=redacted
ERROR 1045 (28000): Access denied for user 'root'@'192.168.233.163' (using password: YES)
我在mysql.user中只有2个条目:
I have only 2 entries in mysql.user:
Host User Password
--------------------------------------
localhost root *blahblahblah
% root [same as above]
我还需要做些什么才能启用远程访问?
What more do I need to do to enable remote access?
编辑
正如下面Paulo所建议的那样,我尝试用IP特定条目替换%的mysql.user条目,所以我的用户表现在看起来像这样:
As suggested by Paulo below, I tried replacing the mysql.user entry for % with an IP specific entry, so my user table now looks like this:
Host User Password
------------------------------------------
localhost root *blahblahblah
192.168.233.163 root [same as above]
然后我重新启动了计算机,但问题仍然存在.
I then restarted the machine, but the problem persists.
推荐答案
Paulo的帮助使我找到了解决方案.它是以下各项的组合:
Paulo's help lead me to the solution. It was a combination of the following:
- 密码中包含美元符号
- 我正在尝试从Linux shell连接
bash外壳将美元符号视为扩展到环境变量,因此我们需要使用反斜杠对其进行转义.顺便说一句,在美元符号是密码的最后一个字符的情况下,我们不必这样做.
The bash shell treats the dollar sign as a special character for expansion to an environment variable, so we need to escape it with a backslash. Incidentally, we don't have to do this in the case where the dollar sign is the final character of the password.
例如,如果您的密码是"pas $ word",则必须通过Linux bash进行以下连接:
As an example, if your password is "pas$word", from Linux bash we must connect as follows:
# mysql --host=192.168.233.142 --user=root --password=pas\$word
这篇关于启用远程MySQL连接:错误1045(28000):用户被拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!