Fix MySQL/MariaDB Error: : 'Access denied for user 'root'@'localhost'

To fix MySQL/Mariadb Error: : 'Access denied for user 'root'@'localhost', you should follow these steps:

Step 1: Open and Edit /etc/my.cnf or /etc/mysql/my.cnf, according to your distro.

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf  (MariaDB 10.3 on Debian 10)

Step 2: Add skip-grant-tables under [mysqld]

Step 3: Restart Mysql

sudo systemctl restart mysql

You must be able to login to mysql now by using the below command mysql -u root -p

Run mysql> flush privileges;

Now, set a new password by

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword'; 

and go back to /etc/my.cnf and remove/comment skip-grant-tables

Again, Restart Mysql, now you can log in with the new password 

0 Komentar