ERROR 1698 (28000): Access denied for user root

This problem occurs from the mysql versions 5.7.+ on wards.
ERROR 1698 (28000): Access denied for user ‘root’@’localhost’.

1. It is because MySql 5.7 by default allow to connect with socket, which means you just connect with sudo mysql

use mysql;

2. Run the following select statement:

SELECT user,authentication_string,plugin,host FROM mysql.user;

+------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+-------------------------------------------+-----------------------+-----------+ | root | | mysql_native_password | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint | *2E686DFA42DA5EC52474BF7E8C326620F8BA2BC0 | mysql_native_password | localhost | +------------------+-------------------------------------------+-----------------------+-----------+ 4 rows in set (0.00 sec)

3. To allow connection with root and password, then update the values in the table with command :

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Admin@123';

4. Then run the flush command.

FLUSH PRIVILEGES;

5. Then run the select command again and you’ll see it has changed :

SELECT user,authentication_string,plugin,host FROM mysql.user;

+------------------+-------------------------------------------+-----------------------+-----------+ | user | authentication_string | plugin | host | +------------------+-------------------------------------------+-----------------------+-----------+ | root | *7BB96B4D3E986612D96E53E62DBE9A38AAA40A5A | mysql_native_password | localhost | | mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost | | debian-sys-maint | *2E686DFA42DA5EC52474BF7E8C326620F8BA2BC0 | mysql_native_password | localhost | +------------------+-------------------------------------------+-----------------------+-----------+ 4 rows in set (0.01 sec)

6. Now exit the mysql and connect again with root user.

mysql -u root -p

7. Check the current active user in MySQL.

select user(),current_user();

ERROR 1698 (28000): Access denied for user root

Leave a Reply

Your email address will not be published. Required fields are marked *