bluebird_lboro bluebird_lboro - 2 months ago 17
MySQL Question

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

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. When I use sudo mysql -u root, i can.

And I don't have the password for the root user of MySQL.

I don't know why.

Answer

It turns out, somehow I got 'root'@'XXXXX-aspire','root'@'localhost' and 'root'@'%'.

When I delete 'root'@'XXXXX-aspire', I can login by mysql -uroot without problem.