MySQL localhost禁止访问

遇到这个问题先确认是否创建了账户


use mysql;
select Host,User from user;

我遇到这个问题是在Centos+Mysql 5.6

我创建了一个example_user@%的账户,但使用mysql -u example_user -h 127.0.0.1 -p无法登录,返回信息显示 Access denied for user ‘example_user’@localhost ,我就一直觉得很奇怪,我用的host明明是127.0.0.1,为什么变成localhost了,而且%应该是匹配所有host才对。

后来经过多次测试,发现在这种环境下,127.0.0.1会被识别为localhost,而且%并不会匹配到localhost,因此,我们只需要创建localhost作为host的账户即可


grant all on example_db.* on "example_user"@"localhost" identified by "your password";
flush privileges;

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注