I am trying to connect to a mysql instance running inside a local Docker Container, but I am getting a
ERROR 1045 (28000): Access denied for user 'root'@'172.17.0.1'
I initialized the container by running:
docker image pull mariadb:10.4
docker run --name mariadbtest -e MYSQL_ROOT_PASSWORD=password -e MYSQL_USER=user -e MYSQL_DATABASE=test -e MYSQL_PASSWORD=password -e MYSQL_ROOT_HOST=localhost -p 3306:3306 -d docker.io/library/mariadb:10.4
When I try to connect to the db using mysql -h localhost -P 3306 --protocol=TCP -u root -p
from the host machine, I get the error mentioned in the title. I am able to use the same command to connect as a user that was initialized in the command that started the Docker container (mysql -h localhost -P 3306 --protocol=TCP -u user -p
) successfully.
I have verified that I can connect to the db from inside the Docker container itself after running docker exec -it mariadbtest bash
and mysql -u root -p
.
I'd appreciate any insights into what's happening.
CodePudding user response:
MYSQL_ROOT_HOST=localhost
should be left out, which then it defaults to %
else its not going to match 172.17.0.1