简体   繁体   English

无法使用Mysql根帐户登录,但是在Ubuntu 16.04中使用sudo命令时可以登录

[英]Can't login with Mysql root account but can login when use sudo command in ubuntu 16.04

Can't login with Mysql root account but can login when use sudo command in ubuntu 16.04 无法使用Mysql根帐户登录,但是在Ubuntu 16.04中使用sudo命令时可以登录

bluebird:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
bluebird:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
bluebird:~$ sudo mysql -uroot
[sudo] password for bluebird: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.7.13-0ubuntu0.16.04.2 (Ubuntu)

Copyright (c) 2000, 2016, 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> 

When I use mysql -u root -p , I can't login. 当我使用mysql -u root -p时 ,我无法登录。 When I use sudo mysql -u root , i can. 当我使用sudo mysql -u root时 ,我可以。

And I don't have the password for the root user of MySQL. 而且我没有MySQL的root用户的密码。

I don't know why. 我不知道为什么

I used the command below: 我使用下面的命令:

use mysql;
select User, Host from user;

It turns out, somehow I got 'root'@'XXXXX-aspire','root'@'localhost' and 'root'@'%'. 原来,以某种方式我得到了'root'@'XXXXX-aspire','root'@'localhost'和'root'@'%'。

When I delete 'root'@'XXXXX-aspire', I can login by mysql -uroot without problem. 当我删除'root'@'XXXXX-aspire'时,我可以通过mysql -uroot登录而没有问题。

Try this as SUDO then try login without sudo 尝试以SUDO身份登录,然后尝试不使用sudo登录

GRANT ALL PRIVILEGES ON *.*  TO 'root'@'localhost';
FLUSH PRIVILEGES;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM