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

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


当前回答

如果您忘记密码或想修改密码。你可以遵循以下步骤:

1 :stop your mysql [root@maomao ~]# service mysqld stop Stopping MySQL: [ OK ] 2 :use “--skip-grant-tables” to restart mysql [root@mcy400 ~]# mysqld_safe --skip-grant-tables [root@cy400 ~]# Starting mysqld daemon with databases from /var/lib/mysql 3 : open a new window and input mysql -u root [root@cy400 ~]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. 4 : change the user database mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed 5 : modify your password your new password should be input in "()" mysql> update user set password=password('root123') where user='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed: 3 Warnings: 0 6 : flush mysql> flush privileges; 7: quit mysql> quit Bye 8: restart mysql [root@cy400 ~]# service mysqld restart; Stopping MySQL: [ OK ] Starting MySQL: [ OK ]

宾果!你可以用用户名和新密码连接你的数据库:

[root@cy400 ~]# mysql -u root -p <br>
Enter password: admin123 <br>
Welcome to the MySQL monitor.  Commands end with ; or \g. <br>
Your MySQL connection id is 2 <br>
Server version: 5.0.77 Source distribution <br>
Type 'help;' or '\h' for help. Type '\c' to clear the buffer. <br>
mysql> quit <br>
Bye

其他回答

操作系统:windows

我的错误信息是:

MySQL ERROR 1045(28000):用户'root'@'localhost'(使用密码:YES)被拒绝访问

我的原因是,我没有打开cmd与管理员权限。

所以我的解决方案是作为管理员打开cmd,然后它就工作了。

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

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

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';

在我的情况下,服务器托管我的代码是发送'@blablabla.amazonaws.com'在用户名的ed时,试图登录MySQL。所以我不得不将%.amazonws.com添加到我的主机的用户配置(dreamhost)中,它通过了

不确定其他人是否会发现这有帮助,但我遇到了同样的错误,并搜索任何匿名用户…但实际上并没有。问题最终是用户帐户被设置为“要求SSL”-这是我在PHPMyAdmin通过进入用户帐户并单击编辑用户的权限发现的。只要我取消了这个选项,一切都按预期工作!

我也有同样的问题,但在我的情况下,解决方案是由eggyal的评论解决的。我也有一个匿名用户,但删除它并不能解决问题。'FLUSH PRIVILEGES'命令仍然有效。

让我感到惊讶的是,我用MySQL Workbench创建了这个用户,我本来希望它能执行完成任务所需的所有功能。