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.
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'@'%'.
When I delete 'root'@'XXXXX-aspire', I can login by mysql -uroot
without problem.
Try this as SUDO then try login without sudo
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost';
FLUSH PRIVILEGES;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.