MySQL Access Denied Troubleshooting

User
admin1@PC-274:~$ ssh -i /home/admin1/.ssh/id_rsa nethues@116.203.33.80 -p 1322
Last login: Mon Apr 7 08:35:01 2025 from 14.141.174.122
[nethues@DB1-alma-4gb-nbg1-2 ~]$ mysql –v
mysql: [ERROR] unknown option '–v'.
[nethues@DB1-alma-4gb-nbg1-2 ~]$ mysql -v
ERROR 1045 (28000): Access denied for user 'nethues'@'localhost' (using password: NO)
[nethues@DB1-alma-4gb-nbg1-2 ~]$ mysql -u dashboardklass_6tghji898u76ty
ERROR 1045 (28000): Access denied for user 'dashboardklass_6tghji898u76ty'@'localhost' (using password: NO)
[nethues@DB1-alma-4gb-nbg1-2 ~]$ mysql -u dashboardklass_6tghji898u76ty -p
Enter password:
ERROR 1045 (28000): Access denied for user 'dashboardklass_6tghji898u76ty'@'localhost' (using password: YES)
Assistant
You're encountering MySQL access errors due to authentication failure. Here's how to proceed:

### ๐Ÿ” **Error Explanation**

– `Access denied for user 'username'@'localhost'` indicates either:
– Incorrect **username**
– Incorrect **password**
– User does **not have privileges** from `localhost`

### โœ… **Steps to Resolve**

#### 1. **Check if MySQL is Running**
Run:

sudo systemctl status mysqld

#### 2. **Login as a User with Privileges**
If you have **`root` access to the server via SSH**, try logging into MySQL as `root`:

sudo mysql -u root

> If it works, you can reset the password or grant permissions to the desired user.

### ๐Ÿ”ง **Reset or Grant Access (If You Get In)**

-- Change password
ALTER USER 'dashboardklass_6tghji898u76ty'@'localhost' IDENTIFIED BY 'yourNewPassword';

-- OR create user if not exists
CREATE USER 'dashboardklass_6tghji898u76ty'@'%' IDENTIFIED BY 'yourNewPassword';

-- Grant privileges (e.g., all privileges on a specific DB)
GRANT ALL PRIVILEGES ON your_database_name.* TO 'dashboardklass_6tghji898u76ty'@'%';

-- Reload privileges
FLUSH PRIVILEGES;

### ๐Ÿšซ **If You Can't Access MySQL at All**

If `sudo mysql` or `sudo mysql -u root` doesn't work:

#### a) Try **`mysql_secure_installation`** to reset root password

#### b) Or **Start MySQL in Safe Mode**:

sudo systemctl stop mysqld
sudo mysqld_safe --skip-grant-tables &
mysql -u root

Then update password:

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

Then exit and restart MySQL:

sudo systemctl restart mysqld

If you're not sure which user has privileges or can't access MySQL at all, let me know โ€” I can walk you through starting it in recovery mode or inspecting config files (`my.cnf`).

User
DB1-alma-4gb-nbg1-2
Public IP: 116.203.33.80
Private IP: 10.0.0.3

and

DB2-ALMA-4GB-hel
Public IP: 37.27.39.31
Private IP: 10.0.0.4

The Plugins on all sites are pointed at the Load balancer IP.

load-balancer-1
Public IP: 167.235.111.58
Private IP: 10.0.0.2

The Load Balancer is targeting the Server "DB1-alma-4gb-nbg1-2"
hetzner cloud

Assistant
Thanks, Neeraj. Based on your setup:

– **DB1** (IP: `116.203.33.80`, Private: `10.0.0.3`) โ€“ Currently targeted by the load balancer
– **DB2** (IP: `37.27.39.31`, Private: `10.0.0.4`) โ€“ Standby or for future failover
– **Load Balancer** (IP: `167.235.111.58`) โ€“ All WordPress plugins connect to this IP
– Youโ€™re trying to manage access to the shared **external database** from multiple WP sites using a **common DB user**

### โœ… Objective

You want to ensure the external DB user (`dashboardklass_6tghji898u76ty`) works across all environments via the load balancer IP.

### ๐Ÿ”’ Important Notes

1. **The MySQL user must be allowed from `%` (any host)** or specifically from the **private network/load balancer IP (10.0.0.2)**.
2. The MySQL user must exist and be granted privileges **on both DB1 and DB2**, in case of failover.
3. Youโ€™ll likely access the DB using the private network IP (10.0.0.3) internally, but your WP plugins point to `167.235.111.58`.

### ๐Ÿ‘‡ What You Should Do on DB1 (Active DB):

#### 1. **Login to MySQL as root**
If you canโ€™t log in, use:

sudo mysql -u root

#### 2. **Create or Update the User**

-- Replace 'yourpassword' with the actual password you want to use
CREATE USER IF NOT EXISTS 'dashboardklass_6tghji898u76ty'@'%' IDENTIFIED BY 'yourpassword';

-- Grant privileges on required database
GRANT ALL PRIVILEGES ON your_database_name.* TO 'dashboardklass_6tghji898u76ty'@'%';

-- Apply changes
FLUSH PRIVILEGES;

> โœ… This allows access from **any host**, including the Load Balancer and all WP sites using it.

### ๐Ÿ” Repeat on DB2 (for redundancy)

SSH into **DB2** (`37.27.39.31`) and repeat the same MySQL steps there so itโ€™s ready for failover.

### ๐Ÿ” Test Connection

From any external server (or within a container), test using:

mysql -h 167.235.111.58 -u dashboardklass_6tghji898u76ty -p

> If it connects and shows databases, youโ€™re good!

Let me know the actual DB name if you want to script this or apply it via Ansible/Docker. Or if `root` login isn't working, Iโ€™ll help you reset it safely.

Leave a Comment

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