MySQL access denied errors usually come from the wrong user, host, password, database grants or Docker environment mismatch.
Symptoms
- Application cannot connect to MySQL.
- mysql client returns Access denied for user.
- Docker app works after rebuild but fails after changing .env.
Likely causes
- Credentials do not match the MySQL user.
- User grants are for a different host.
- Docker volume preserved old database users.
- Application reads a different .env than expected.
Fix steps
- Confirm host, port, database, user and password.
- Check grants for user@host.
- Inspect Docker Compose env variables and persistent volumes.
- Avoid changing root credentials without reinitializing intentionally.
Verify the fix
- Connect with mysql CLI using the same host and credentials.
- Log the configured host without printing passwords.
- Restart the app after config changes.
FAQ
Why did changing .env not fix MySQL?
Existing database volumes may keep the old initialized users and passwords.
Is localhost the same as 127.0.0.1?
Not always. MySQL may treat socket and TCP connections differently.
Related tools and guides
Last updated: May 18, 2026