刚开始接触mysql。我使用 root 登录并按照在线引用创建新用户:
mysql> CREATE USER 'abc'@'%' IDENTIFIED BY '111111';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'abc'@'%' WITH GRANT OPTION;
然后我退出并尝试使用新用户登录:
mysql --user=abc --password=111111 mysql
但是得到一个错误信息:
Access denied for user 'abc'@'localhost' (using password: YES)
我错过了什么吗?
最佳答案
运行这个来工作
FLUSH PRIVILEGES
一旦您为您的用户授予了所需的权限,您将需要 FLUSH 权限以完成设置并使新设置生效。为此,请在 SQL 命令提示符下运行此命令:
[编辑]
如果您还想从本地主机连接,您应该创建另一个帐户。
It is necessary to have both accounts for 'user' to be able to connect from anywhere as 'user'. Without the localhost account, the anonymous-user account for localhost that is created by mysql_install_db would take precedence when 'user' connects from the local host. As a result, 'user'would be treated as an anonymous user. The reason for this is that the anonymous-user account has a more specific Host column value than the 'user'@'%' account and thus comes earlier in the user table sort order. )
仅供引用:http://dev.mysql.com/doc/refman/5.5/en/adding-users.html
关于mysql新用户访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14098242/