首先让我提一下,我已经看了很多建议的问题,但没有找到相关的答案。这就是我正在做的。

我连接到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)的访问被拒绝


当前回答

这可能只适用于少数人,但事实就是这样。不要用感叹号!在你的密码里。

我做到了,并使用MariaDB得到了上述错误。当我把它简化成数字和字母时,它是可行的。其他字符,如@和$工作得很好-我在同一实例的不同用户中使用了这些字符。

这个地址的第五次回复让我找到了解决办法。

其他回答

这是以下两者之间的区别:

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;

我为自己找到的最好的解决办法是。

我的用户是声纳,每当我试图从外部或其他机器连接到我的数据库,我得到错误

ERROR 1045 (28000): Access denied for user 'sonar'@'localhost' (using password: YES)

此外,我正在尝试从另一台机器和通过詹金斯工作我的URL访问是

alm-lt-test.xyz.com

如果你想远程连接,你可以用以下不同的方式指定它:

mysql -u sonar -p -halm-lt-test.xyz.com
mysql -u sonar -p -h101.33.65.94
mysql -u sonar -p -h127.0.0.1 --protocol=TCP
mysql -u sonar -p -h172.27.59.54 --protocol=TCP

要访问这个URL,你只需要执行以下查询。

GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'alm-lt-test.xyz.com' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'127.0.0.1' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'172.27.59.54' IDENTIFIED BY 'sonar';

I discovered yet another case that appears on the surface to be an edge case; I can export to the file system, via SELECT INTO .. OUTFILE as root, but not as regular user. While this may be a matter of permissions, I've looked at that, and see nothing especially obvious. All I can say is that executing the query as a regular user who has all permissions on the data base in question returns the access denied error that led me to this topic. When I found the transcript of a successful use of SELECT INTO … OUTFILE in an old project, I noticed that I was logged in as root. Sure enough, when I logged in as root, the query ran as expected.

我也遇到了类似的问题——当我第一次尝试以root用户登录MySQL时,它告诉我访问被拒绝。原来我忘了用sudo…

所以,如果你第一次尝试root失败了,试试:

sudo mysql -u root -p

然后输入密码,就可以了。

好吧,我不确定,但可能是mysql安装目录中的my.cnf文件是罪魁祸首。 注释掉这一行,问题就可以解决了。

bind-address = 127.0.0.1