version: "3"
services:
db:
image: mysql:5.7.34
command: --init-file /var/lib/docker/volumes/db/init.sql --innodb-use-native-aio=0 --explicit_defaults_for_timestamp=false
volumes:
- ./db:/var/lib/docker/volumes/db
restart: always
environment:
MYSQL_ROOT_PASSWORD: test
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: test
MYSQL_ROOT_HOST: '%'
ports:
- 3306:3306
adminer:
image: adminer
restart: always
ports:
- 8081:8080
depends_on:
- db
app:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- ./src:/app/src
ports:
- "8000:8000"
depends_on:
- db
I have a docker compose like this. When I run, I can’t connect with db. It showed ERR:
ER_HOST_NOT_PRIVILEGED: Host '172.18.0.3' is not allowed to connect to this MySQL server
.
I can connect if config cmd: GRANT ALL PRIVILEGES ON . TO ‘test’@’%’ IDENTIFIED BY ‘test’ WITH GRANT OPTION;
I want to connect without cmd grant because sometimes it can connect without cmd config. What should I fix this docker?
Connect DB without config cmd
Please include the exact error message
You appear to have neglected to map/create a volume to persist MySQL’s data directory. Which container is
172.18.0.3
and what code / app / credentials (host, user, pass, db_name) is attempting to connect todb
?