首先让我提一下,我已经看了很多建议的问题,但没有找到相关的答案。这就是我正在做的。
我连接到Amazon EC2实例。我可以用这个命令登录MySQL根目录:
mysql -u root -p
然后我用host %创建了一个新的用户帐单
CREATE USER 'bill'@'%' IDENTIFIED BY 'passpass';
授予用户bill的所有权限:
grant all privileges on *.* to 'bill'@'%' with grant option;
然后我退出root用户,尝试用bill登录:
mysql -u bill -p
输入正确的密码并得到以下错误:
错误1045(28000):用户“账单”@“localhost”(使用密码:YES)的访问被拒绝
这是以下两者之间的区别:
CREATE USER 'bill'@'%' IDENTIFIED BY 'passpass';
and
CREATE USER 'bill'@'localhost' IDENTIFIED BY 'passpass';
检查:
mysql> select user,host from mysql.user;
+---------------+----------------------------+
| user | host |
+---------------+----------------------------+
| bill | % | <=== created by first
| root | 127.0.0.1 |
| root | ::1 |
| root | localhost |
| bill | localhost | <=== created by second
+---------------+----------------------------+
命令
mysql -u bill -p
隐式访问'bill'@'localhost',而不是'bill'@'%'。
“bill”@“localhost”没有权限
你会得到错误:
ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)
解决问题:
CREATE USER 'bill'@'localhost' IDENTIFIED BY 'passpass';
grant all privileges on . to 'bill'@'localhost' with grant option;