How to fix Access denied for user ‘root’@’localhost’ error

At times you try to access the database via the terminal and you run into the error ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)Even using a password for the root user still returns the same error.This guide will take you through how to address the issue for a

Last updated 30 Nov 2026Also in: Databases

At times you try to access the database via the terminal and you run into the error

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Even using a password for the root user still returns the same error.

This guide will take you through how to address the issue for a mariadb database server

Login to the server as root user.

Shutdown or stop the mariadb database server.

**systemctl stop mariadb.service**

Confirm the status that the db is offline.

systemctl status mariadb.service

Restart the database in safe mode by typing the command below.

sudo mysqld_safe --skip-grant-tables --skip-networking &

You will see an output as shown below

Access the database using the command below.

**mysql -u root**

Use the mysql database

**use mysql**

Update root password.

**UPDATE user SET password=PASSWORD('new-password-here') WHERE user='root';**

or

**ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password-here';**

Stop MariaDB Safe Mode

pkill -f mysqld_safe pkill -f mysqld

Restart the database in normal mode.

sudo systemctl start mariadb

Done.