Failed to connect to mysql server using user “root” and password “***”: Access denied for user ‘root’@’localhost’

When trying to login or give SQL\ database access to an application, the following error can be resolved by

MariaDB [(none)]> mysql -u root -p

MariaDB [(none)]> UPDATE mysql.user SET plugin = 'mysql_native_password', Password = PASSWORD('NEWPASSWORD') WHERE User = 'root';

The reason for this is when MariaDB\ MySQL is being setup, if the password is not set for root, the above error occurs.

by typing the below

MariaDB [(none)]> select User,host,plugin from mysql.user; 

you can see that on MariaDB the result would be unix_socket , indicating that you can login with mysql command when logged in as root , but the above error would occur when trying thrrough another user account. Finally run

MariaDB [(none)]> FLUSH PRIVILEGES;
Interesting || Helpful?
10

Leave a Reply

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