MySQL Access Denied Troubleshooting
April 7, 2025 ยท AI Conversations
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)
—
### ๐ **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`).
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
– **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.