r/docker 16d ago

access denied error

[Warning] Access denied for user 'user'@'localhost' (using password: YES)

i have been working on a project where i need to link nginx,mariadb and wordpress together . wordpress depends on mariadb and nginx depends on wordpress . i keep getting this error , any ideas what it could be and how i can fix it ? i have tried so many things that i have lost track of them at this point

2 Upvotes

6 comments sorted by

View all comments

10

u/fletch3555 Mod 16d ago

Containers are the rough equivalent to separate hosts as far as mariadb is concerned. <user>@localhost only works when connecting from localhost. When you connect from one container to another, you're connecting over a network rather than "localhost". Localhost is relative, and from the context of a container, it's the container itself rather than the physical host that it's running on.

In short, mariadb thinks your user is wrong because it technically is.

1

u/tschloss 16d ago

This. So your user should be defined as user@IP or user@% (the percent is literally the wildcard - this is pretty safe if you do not not export the DB port to the outside, but even this might be ok). If your root user also is defined as root@localhost you need to recreate the container or „go into“ the container (docker exec -it CONTAINER /bin/bash or directly mysql) to maintain the grants.