A reference guide to the database connection and permission errors developers hit most often, across MySQL/MariaDB, PostgreSQL, and MongoDB, with direct fixes.
MySQL/MariaDB: "Access denied for user"
ERROR 1045 (28000): Access denied for user 'appuser'@'localhost'
Verify the password is correct, and confirm the user actually has privileges on the target database:
SHOW GRANTS FOR 'appuser'@'localhost';
If missing, grant them:
GRANT ALL PRIVILEGES ON myapp.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
MySQL/MariaDB: "Can't connect to MySQL server"
Verify the service is running:
sudo systemctl status mysql
If connecting remotely, confirm bind-address in the config isn't restricted to 127.0.0.1 only, and that the firewall allows the connection.
MySQL/MariaDB: "Too many connections"
SHOW VARIABLES LIKE 'max_connections';
Either the application isn't closing connections properly (fix at the app layer first), or max_connections genuinely needs raising — see How to Tune MySQL/MariaDB Performance for a VPS.
PostgreSQL: "password authentication failed for user"
Verify the password, and check the authentication method configured in:
sudo nano /etc/postgresql/*/main/pg_hba.conf
The method (e.g. scram-sha-256, md5) must match what the client supports.
PostgreSQL: "FATAL: no pg_hba.conf entry for host"
The connecting IP isn't authorized. Add an entry:
host myapp appuser YOUR_IP/32 scram-sha-256
sudo systemctl restart postgresql
PostgreSQL: "database does not exist"
sudo -u postgres psql -l
Confirms the exact database name and whether it was actually created.
MongoDB: "Authentication failed"
Confirm you're specifying the correct authentication database:
mongosh -u admin -p --authenticationDatabase admin
MongoDB: "connect ECONNREFUSED 127.0.0.1:27017"
sudo systemctl status mongod
If MongoDB is running but the app still can't connect, verify it's not bound only to a different interface than expected.
General: Connection Works via CLI But Not from the Application
This usually means the app is using different credentials, host, or port than tested manually. Double-check the exact connection string/environment variables the application is actually using — not what you assume they are.
General: Firewall Blocking a Remote Connection
sudo ufw status
Confirm the specific port and source IP are explicitly allowed.
Diagnostic Checklist
- Is the database service actually running?
systemctl status - Can you connect locally via the CLI client with the same credentials the app uses?
- Does the user have the correct privileges on the specific database?
- Is the firewall allowing the connection, if remote?
- Does the authentication method/config file allow this specific host/user combination?
Related Articles
- How to Install and Secure MySQL 8 on Ubuntu & Debian
- How to Install PostgreSQL on Ubuntu & Debian
- Database Security Checklist: Protecting MySQL, PostgreSQL & MongoDB
