
>在ubuntu服务器上停止防火墙:iptables -F.也试过sudo服务ufw停止.
>在/etc/mysql/my.cnf中注释“bind-address”并重新启动mysql.
>在mysql中添加用户:CREATE USER’test’@’%’IDENTIFIED BY’testpwd’;
>授予所有特权. ”””””””””””””””””””””””””
> FLUSH特权;
>我可以通过“选择主机,来自mysql.user的用户”看到新用户的输入;
>再次重启mysql.还是一样的错误!
>现在我想也许防火墙还有一些问题,所以补充说:iptables -A INPUT -i eth0 -p tcp –destination-port 3306 -j ACCEPT
问题仍然存在.帮助将非常感激,否则我将陷入严重的麻烦.
这意味着在网络级别一切正常,因为要拒绝作为给定用户的访问,服务器必须已经了解您尝试连接的用户.因此,网络,防火墙,路由等等都必须正常工作;服务器必须正在监听等.
问题在于“简单”在身份验证中.
尝试本地连接到数据库(以覆盖身份验证)并检查权限表:
USE mysql;
SELECT User, Host, Password from user WHERE User = 'test';
并记住您感兴趣的行是提到IP的行(因为错误消息指定IP,而不是主机名 – 在这种情况下,它可能是DNS问题;主机名是主机名,服务器认为你是来自,而不是你真正来自的主机名.
用户/主机匹配为from more specific to less specific.所以如果你已经有:
user host password
test 1.2.3.4 foo
跑了,
GRANT... TO test@'%' ... PASSWORD bar
……除了1.2.3.4之外,这个授权可以在任何地方使用,密码将保持为’foo’.
从手册(上面的链接):
The server uses sorting rules that order rows with the most-specific
Host values first. Literal host names and IP addresses are the most
specific. (The specificity of a literal IP address is not affected by
whether it has a netmask, so 192.168.1.13 and
192.168.1.0/255.255.255.0 are considered equally specific.) The pattern ‘%’ means “any host” and is least specific. The empty string
” also means “any host” but sorts after ‘%’. Rows with the same Host
value are ordered with the most-specific User values first (a blank
User value means “any user” and is least specific). For rows with
equally-specific Host and User values, the order is indeterminate.
你可能会被迫做
USE mysql;
DELETE FROM user WHERE User = 'test';
GRANT ALL PRIVILEGES ON database.* TO 'test'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
确保授权表中没有涉及用户“测试”的虚假行.
(另外,GRANT应该是,我认为,
GRANT ALL PRIVILEGES ON databasename.*
)
安全疑问(与答案无关)
上面的手册说:文字IP地址的特殊性不受它是否有网络掩码的影响,因此192.168.1.13和192.168.1.0/255.255.255.0被认为是同等特定的.
现在乍一看127.0.0.1/0.0.0.0似乎对localhost非常具体(且无害).网络掩码,如果我没有弄错的话,确保它等于%,除了它非常具体并将首先运行.因此
test bar %
test localfoo 127.0.0.1/0.0.0.0
意味着从任何地方进行测试的密码根本不是“bar”,而是“localfoo”.
没有人会错误地插入这样的补助金,但是有错误和错误.
转载注明原文:mysql – 访问被拒绝用户’test’@’ip'(使用密码:YES) - 乐贴网