1

Whenever I run

mysql -u root mysql

I get an error like:

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

I tried running

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

But I got

bash: syntax error near unexpected token `('

Then I ran

$ mysql>FLUSH PRIVILEGES

I still get an error:

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

I've tried all possible solution on Stack Overflow or any other website.

I've also tried deleting and re-installing MySQL. I am still not able to reset the password.

Kulfy
  • 17,696

1 Answers1

1

Use sudo and your current user's password (because within Ubuntu 18.04 the default authentication method for the MySQL's root user is socket authentication):

$ 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> 

If I try to log in into mysql DBS without sudo I get the same results:

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

In order to use mysql -u root -p you need to create mysql_native_password for the MySQL's root user as it is decried here.

Kulfy
  • 17,696
Gryu
  • 7,559
  • 9
  • 33
  • 52