运行 MySQL 时出现“拒绝用户访问:‘root@localhost’(使用密码:否)”

运行 MySQL 时出现“拒绝用户访问:‘root@localhost’(使用密码:否)”

每当我跑步

mysql -u root mysql

我收到如下错误:

ERROR 1698 (28000): Access denied for user: 'root@localhost'

我尝试跑步

update user set authentication_string=password('akshansh') where USER='root'

但我得到了

bash: syntax error near unexpected token `('

然后我就跑了

$ mysql>FLUSH PRIVILEGES

我仍然收到错误:

ERROR 1045 (28000): Access denied for user: 'root@localhost' (using password: NO)

我已经尝试了 Stack Overflow 或任何其他网站上的所有可能的解决方案。

我也尝试过删除并重新安装 MySQL。但仍然无法重置密码。

答案1

使用sudo和您当前用户的密码(因为在 Ubuntu 18.04 中 MySQL 的 root 用户的默认身份验证方法是套接字身份验证):

$ sudo mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.29-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2020, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> 

如果我尝试登录到 mysql DBS,而不sudo获得相同的结果:

$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'

为了使用你需要为MySQL的用户mysql -u root -p创建它被谴责mysql_native_passwordroot这里

相关内容