---
title: "How to fix Access denied for user ‘root’@’localhost’ error"
description: "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…"
url: "https://truehost.com/support/knowledge-base/how-to-fix-access-denied-for-user-rootlocalhost-error/"
updated: "2024-11-28"
category: MySQL
---

# 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 mariadb database server
```

Login to the server as root user.

Shutdown or stop the mariadb database server.

`systemctl stop mariadb.service`

![](https://truehost.com/support/wp-content/uploads/2024/11/image-690-1024x229.png)

Confirm the status that the db is offline.

**`systemctl status mariadb.service`**

![](https://truehost.com/support/wp-content/uploads/2024/11/image-691-1024x243.png)

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

![](https://truehost.com/support/wp-content/uploads/2024/11/image-692-1024x182.png)

Access the database using the command below.

`mysql -u root`

![](https://truehost.com/support/wp-content/uploads/2024/11/image-693-1024x288.png)

Use the mysql database

`use mysql`

![](https://truehost.com/support/wp-content/uploads/2024/11/image-694-1024x188.png)

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_safepkill -f mysqld`**

Restart the database in normal mode.

**`sudo systemctl start mariadb`**

![](https://truehost.com/support/wp-content/uploads/2024/11/image-695.png)

Done.
