The app gets "password authentication failed" or "Access denied" from the database. What do you check?

IntermediateTroubleshootingDatabase connections in apps
Answer

Short answer

The network path works — the server answered — but login was rejected. Check the username and password actually reaching the app (env var/secret value, typos, trailing newline, URL-encoding), whether the user exists for that host, whether the password was rotated, and database-specific rules like PostgreSQL's pg_hba.conf or MySQL's 'user'@'host'.

Checklist

  1. What the app really has:
    kubectl exec deploy/orders -- printenv | grep DB_
    kubectl get secret orders-db -o jsonpath='{.data.password}' | base64 -d | od -c | tail -2   # trailing \n?
    
    Secrets created with echo "pass" | base64 include a newline — use echo -n.
  2. Test the same credentials manually with psql / mysql from the pod.
  3. User/host rules:
    • MySQL: SELECT user, host FROM mysql.user; — 'app'@'localhost' can't log in from 10.0.1.5.
    • Postgres: no pg_hba.conf entry → add a rule; role needs LOGIN.
  4. Rotation — was the password rotated in the vault but the pods still use the old one? Restart pods or use a reloader.
  5. Special characters not URL-encoded in the connection string.
  6. Wrong database / authSource (MongoDB needs authSource=admin for admin-created users).

What to say in the interview

"Authentication errors mean the network is fine. I verify the exact secret value inside the pod — trailing newlines and URL-encoding are classic — test it with the CLI client, then check host-based rules like MySQL user@host or pg_hba.conf, and whether a rotation left pods with a stale password."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Connecting apps to databases

More on Database connections in apps