SQLSTATE[28000] [1045] 用户 'root'@'localhost' 的访问被拒绝(使用密码:YES)

SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

我是 Linux 的新手。我正在尝试 运行 本地主机上的一个项目。它有效,但现在我收到此错误:

SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

我试过这样修改密码:

sudo dpkg-reconfigure mysql-server-5.5

还是没有结果。 如何解决?

mysql -u root -p

然后它会提示您输入密码。如果失败,则肯定是用户名或密码不正确。

您需要将root@localhost空白的密码设置为其他。

SET PASSWORD FOR root@localhost=PASSWORD('root');