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

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


当前回答

当你的密码包含一些特殊字符,如@,$等,也会发生这种情况。 为了避免这种情况,你可以把password用单引号括起来:

$ mysql -usomeuser -p's0mep@$$w0Rd'

或者在输入时不用密码。请留空,然后在终端要求时输入。这是推荐的方法。

$ mysql -usomeuser -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 191
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

其他回答

在Windows上,解决方法如下:

错误1045(28000):拒绝访问用户'root'@'localhost'(使用密码:NO)

从控制面板卸载mysql 删除C:\Program Files,C:\Program Files (x86)和C:\ProgramData目录下的MySql文件夹 安装mysql

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

这太迟了

我尝试了所有这些其他答案,并运行了许多不同版本的mysql -u root -p,但从来没有运行过


Mysql -u root -p

然后按[ENTER]输入密码。


一旦我这么做了,就成功了。希望这能帮助到一些人。

我通过删除旧的错误用户“账单”条目来解决这个问题(这是重要的部分:都来自mysql。用户和mysql.db),然后创建和前面一样的用户:

FLUSH PRIVILEGES;
CREATE USER bill@localhost IDENTIFIED BY 'passpass';
grant all privileges on *.* to bill@localhost with grant option;
FLUSH PRIVILEGES;

工作完毕,用户正在连接。现在我将删除一些特权从它:)

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

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