Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

What to do when #1698 - access denied for user 'root'@'localhost'?

Asked by David Edmunds Mar 16, 2023 814 views 1 answer
Share

About this question

 I discovered that my phpmyadmin cannot login with my root password. So I updated the password as follow:

# mysql 
mysql> UPDATE user set authentication_string=password('secret') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
After doing this I tried to connect with my new root password:
# sudo -u www-data mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
I don't understand why I am still denied.
mysql> show grants for 'root'@'localhost';
+---------------------------------------------------------------------+
| Grants for root@localhost                                           |
+---------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION        |
+---------------------------------------------------------------------+
2 rows in set (0.00 sec)
mysql> select USER(),CURRENT_USER();
+----------------+----------------+
| USER()         | CURRENT_USER() |
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
1 row in set (0.00 sec)
I tried with:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
and it worked, but I have absolutely no idea of why any other methods do not work.

What is bizarre is that before I could connect in root with # mysql. Now I have to do # mysql -uroot -p. What did I change?

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.