0

I installed mysql in Ubuntu 20.04.

Problem -

Case 1: I have default root user. I can login using sudo mysql but cannot login using mysql -u root -p.

Case 2: I created another user 'local'. I can login using mysql -u local -p and by giving password I set. But problem is if I give wrong password, it still logs me in. I don't know why.

I followed this ERROR 1698 (28000): Access denied for user 'root'@'localhost' but this didn't help me. I followed other topics too like creating new user for mysql etc. I cannot access from workbench or from python script too.

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

Hemant Sah
  • 29
  • 7

1 Answers1

0

Login to mysql using sudo mysql -u root

Give your su password and it will login without mysql password.

Run following commands:

USE mysql;
UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
exit;

Restart:

sudo systemctl restart mysql.service

After that, run commands to secure MySQL server and create a new root password.

sudo mysql_secure_installation

When prompted, answer the following questions :

  • New password: Enter password
  • Re-enter new password:
  • Repeat password
  • Remove anonymous users? [Y/n]: Y
  • Disallow root login remotely? [Y/n]: Y
  • Remove test database and access to it? [Y/n]: Y
  • Reload privilege tables now? [Y/n]: Y

Next time, type following command in terminal to login:

sudo mysql -u root -p

Then type mysql password you set recently to sign in. Good Luck, this worked for after continuous wasting several hours on this thing and following tens of tutorials. By doing this, I was finally able to establish connection in workbench and in my python scripts.

Hemant Sah
  • 29
  • 7