# DOCKER INSTALLATION: Can't Connect to MYSQL Server

**URL:** <https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710>\
**Category:** Mautic 5 Install/Upgrade Support\
**Created:** [January 9, 2025, 10:29pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710 "2025-01-09T22:29:28Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![3von](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/3von/32/13516_2.png) [@3von](https://forum.mautic.org/u/3von)\
**Post date:** [January 9, 2025, 10:29pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/1 "2025-01-09T22:29:28Z")

</div>

**Your software**  
My Mautic version is: 5  
My PHP version is: 8  
My Database type and version is: MYSQL

**Your problem**  
My problem is: Docker installation can’t connect to MYSQL

These errors are showing in the log:  
mautic\_web-1 | mysqladmin: connect to server at ‘db.farm-mail-docker’ failed  
mautic\_web-1 | error: ‘Host ‘172.19.0.3’ is not allowed to connect to this MySQL server’  
mautic\_web-1 | mysqladmin: connect to server at ‘db.farm-mail-docker’ failed  
mautic\_web-1 | error: ‘Host ‘172.19.0.3’ is not allowed to connect to this MySQL server’  
mautic\_web-1 | mysqladmin: connect to server at ‘db.farm-mail-docker’ failed  
mautic\_web-1 | error: ‘Host ‘172.19.0.3’ is not allowed to connect to this MySQL server’  
mautic\_web-1 | mysqladmin: connect to server at ‘db.farm-mail-docker’ failed  
mautic\_web-1 | error: ‘Host ‘172.19.0.3’ is not allowed to connect to this MySQL server’  
mautic\_web-1 | mysqladmin: connect to server at ‘db.farm-mail-docker’ failed  
mautic\_web-1 | error: ‘Host ‘172.19.0.3’ is not allowed to connect to this MySQL server’

Steps I have tried to fix the problem:  
-reviewed config and made sure all the env variables were set  
-reviewed old posts for solutions  
-reviewed github issues for solutions

My config:

```auto
**docker-compose.yml**
x-mautic-volumes:
  &mautic-volumes
  - ./config:/var/www/html/config:z
  - ./logs:/var/www/html/var/logs:z
  - ./media/files:/var/www/html/docroot/media/files:z
  - ./media/images:/var/www/html/docroot/media/images:z
  - ./cron:/opt/mautic/cron:z
  - mautic-docroot:/var/www/html/docroot:z
 
services:
  db:
    image: mysql:8.0
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    volumes:
      - mysql-data:/var/lib/mysql
    healthcheck:
      test: mysqladmin --user=$$MYSQL_USER --password=$$MYSQL_PASSWORD ping
      start_period: 5s
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - default
 
  nginx:
    image: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
      - mautic-docroot:/var/www/html/docroot:z
    depends_on:
      - mautic_web
    ports:
      - 8002:80
    networks:
      - default
 
  mautic_web:
    image: mautic/mautic:5-fpm
    links:
      - db:mysql
    volumes: *mautic-volumes
 
    environment:
      - DOCKER_MAUTIC_LOAD_TEST_DATA=${DOCKER_MAUTIC_LOAD_TEST_DATA}
      - DOCKER_MAUTIC_RUN_MIGRATIONS=${DOCKER_MAUTIC_RUN_MIGRATIONS}
    env_file:
      - .mautic_env
    healthcheck:
      test: cgi-fcgi -bind -connect 192.168.1.125:9000
      start_period: 5s
      interval: 5s
      timeout: 5s
      retries: 100
    depends_on:
      db:
        condition: service_healthy
    networks:
      - default
 
  mautic_cron:
    image: mautic/mautic:5-fpm
    links:
      - db:mysql
    volumes: *mautic-volumes
    environment:
      - DOCKER_MAUTIC_ROLE=mautic_cron
    env_file:
      - .mautic_env
    depends_on:
      mautic_web:
        condition: service_healthy
    networks:
      - default
 
  mautic_worker:
    image: mautic/mautic:5-fpm
    links:
      - db:mysql
    volumes: *mautic-volumes
    environment:
      - DOCKER_MAUTIC_ROLE=mautic_worker
    env_file:
      - .mautic_env
    depends_on:
      mautic_web:
        condition: service_healthy
    networks:
      - default
 
volumes:
  mysql-data:
  mautic-docroot:
 
networks:
  default:
    name: ${COMPOSE_PROJECT_NAME}-docker
 
**.env**
COMPOSE_PROJECT_NAME=farm-mail
COMPOSE_NETWORK=${COMPOSE_PROJECT_NAME}-docker
MYSQL_HOST=db.${COMPOSE_NETWORK}
MYSQL_PORT=3306
MYSQL_DATABASE=mautic_db
MYSQL_USER=evon
MYSQL_PASSWORD=fmq2108b
MYSQL_ROOT_PASSWORD=fmq2108b
DOCKER_MAUTIC_RUN_MIGRATIONS=false
DOCKER_MAUTIC_LOAD_TEST_DATA=false
 
**.mautic_env**
COMPOSE_PROJECT_NAME=farm-mail
COMPOSE_NETWORK=${COMPOSE_PROJECT_NAME}-docker
MYSQL_HOST=db.${COMPOSE_NETWORK}
MYSQL_PORT=3306
MYSQL_DATABASE=mautic_db
MYSQL_USER=evon
MYSQL_PASSWORD=fmq2108b
MYSQL_ROOT_PASSWORD=fmq2108b
DOCKER_MAUTIC_RUN_MIGRATIONS=false
DOCKER_MAUTIC_LOAD_TEST_DATA=false
root@mail-list-server:~/mautic# cat .mautic_env 
# use this file for environment variables that can be used.
# see https://docs.mautic.org/en/5.x/
 
MAUTIC_DB_HOST="${MYSQL_HOST}"
MAUTIC_DB_PORT="${MYSQL_PORT}"
MAUTIC_DB_DATABASE="${MYSQL_DATABASE}"
MAUTIC_DB_USER="${MYSQL_USER}"
MAUTIC_DB_PASSWORD="${MYSQL_PASSWORD}"
 
MAUTIC_MESSENGER_DSN_EMAIL="doctrine://default"
MAUTIC_MESSENGER_DSN_HIT="doctrine://default"

```

---

<div class="post-metadata">

**Author:** ![imog](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/imog/32/3813_2.png) [@imog](https://forum.mautic.org/u/imog)\
**Post date:** [January 11, 2025, 5:52pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/2 "2025-01-11T17:52:07Z")

</div>

Looks like the MySQL account you use in the mautic\_web instance has not the required rights to use the database. In MySQL there is an IP ACL additionally to the user/password.

You don’t mention if the database already exists or you like to create a new one? If the later is true then this is wrong  
DOCKER\_MAUTIC\_LOAD\_TEST\_DATA=false  
and needs to be set to  
DOCKER\_MAUTIC\_LOAD\_TEST\_DATA=true  
to create a new database.

---

<div class="post-metadata">

**Author:** ![3von](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/3von/32/13516_2.png) [@3von](https://forum.mautic.org/u/3von)\
**Post date:** [January 11, 2025, 7:53pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/3 "2025-01-11T19:53:35Z")

</div>

Thanks for taking the time to reply. I don’t know what you mean by IP ACL. I changed this value “DOCKER\_MAUTIC\_LOAD\_TEST\_DATA=true” according to your instructions but the same issue persists.

---

<div class="post-metadata">

**Author:** ![imog](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/imog/32/3813_2.png) [@imog](https://forum.mautic.org/u/imog)\
**Post date:** [January 11, 2025, 10:42pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/4 "2025-01-11T22:42:21Z")

</div>

Try to open a shell in your web container:

```auto
docker exec -it mautic_web bash

```

Then try to connect to your database:

```auto
mysql -hdb.farm-mail-docker -uevon -pfmq2108b

```

You should get a connection prompt of MySQL, like that:

```auto
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 52563
Server version: 8.0.40 MySQL Community Server - GPL

```

If you got “access denied” instead, try to use the root user, to connect:

```auto
mysql -hdb.farm-mail-docker -uroot -pfmq2108b

```

If that get’s the same, there is a problem with the database. Try to delete the locally mapped DB files inside /var/lib/mysql/ on your host.

The setting  
DOCKER\_MAUTIC\_LOAD\_TEST\_DATA=true  
will cause this inside entrypoint\_mautic\_web.sh to be executed:

```auto
# prepare mautic with test data
if ["$DOCKER_MAUTIC_LOAD_TEST_DATA" = "true"]; then
	su -s /bin/bash www-data -c 'php /var/www/html/bin/console doctrine:migrations:sync-metadata-storage'
	# mautic installation with dummy password and email, as the next step (doctrine:fixtures:load) will overwrite those
	su -s /bin/bash www-data -c 'php /var/www/html/bin/console mautic:install --force --admin_email willchange@mautic.org --admin_password willchange http://localhost'
	su -s /bin/bash www-data -c 'php /var/www/html/bin/console doctrine:fixtures:load -n'
fi

```

which will install a basic database structure if none exists. But as you can see, the database is persistet on the host running the docker containers and so you need to “docker compose down”, delete the local DB files and “docker compose up -d” again, to have it recreated.

---

<div class="post-metadata">

**Author:** ![3von](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/3von/32/13516_2.png) [@3von](https://forum.mautic.org/u/3von)\
**Post date:** [January 11, 2025, 11:10pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/5 "2025-01-11T23:10:11Z")

</div>

> [@imog](#):
>
> `mysql -hdb.farm-mail-docker -uevon -pfmq2108b`

Getting the same errors. /var/lib/mysql does’t exist.

---

<div class="post-metadata">

**Author:** ![imog](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/imog/32/3813_2.png) [@imog](https://forum.mautic.org/u/imog)\
**Post date:** [January 12, 2025, 8:47am UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/6 "2025-01-12T08:47:04Z")

</div>

Please check the database logs

```auto
docker logs db

```

to ensure a proper startup. If it starts correctly i assume something is wrong with the setup of the database, because of the access denied.

According to your docker-compose.yml file the MySQL database files are stored in an “named volume” called “mysql-data”. This volume will persist, and so it’s data, even if you rebuild the containers. You should remove that volume before rebuilding. Try to start from scratch (delete ALL data):

```auto
docker-compose rm -fsv
docker system prune -a

```

Then start over again

```auto
docker-compose up -d

```

---

<div class="post-metadata">

**Author:** ![3von](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/3von/32/13516_2.png) [@3von](https://forum.mautic.org/u/3von)\
**Post date:** [January 12, 2025, 1:54pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/7 "2025-01-12T13:54:29Z")

</div>

After running those commands. This is the error I get

```auto
/mysqld/mysqld.sock' exists!
farm-mail_mautic_web_1 | mysqladmin: connect to server at '' failed
farm-mail_mautic_web_1 | error: 'Can't connect to server on 'localhost' (111)'
farm-mail_mautic_web_1 | Check that mariadbd is running and that the socket: '/run/mysqld/mysqld.sock' exists!

```

---

<div class="post-metadata">

**Author:** ![3von](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/3von/32/13516_2.png) [@3von](https://forum.mautic.org/u/3von)\
**Post date:** [January 12, 2025, 2:29pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/8 "2025-01-12T14:29:08Z")

</div>

> [@imog](#):
>
> `docker system prune -a`

I decided to start from scratch with the original docker-compose file to make sure there weren’t any changes I made to it that screwed things up. However, now I’m back to the same error smh. I deleted and pruned everything before I re-installed.

```auto
mautic_web-1 | mysqladmin: connect to server at 'db.farm-mail-docker' failed
mautic_web-1 | error: 'Host '172.18.0.3' is not allowed to connect to this MySQL server'

```

```auto
root@mail-list-server:~/mautic# cat docker-compose.yml
x-mautic-volumes:
  &mautic-volumes
  - ./config:/var/www/html/config:z
  - ./logs:/var/www/html/var/logs:z
  - ./media/files:/var/www/html/docroot/media/files:z
  - ./media/images:/var/www/html/docroot/media/images:z
  - ./cron:/opt/mautic/cron:z
  - mautic-docroot:/var/www/html/docroot:z

services:
  db:
    image: mysql:8.0
    environment:
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
    volumes:
      - mysql-data:/var/lib/mysql
    healthcheck:
      test: mysqladmin --user=$$MYSQL_USER --password=$$MYSQL_PASSWORD ping
      start_period: 5s
      interval: 5s
      timeout: 5s
      retries: 10
    networks:
      - default

  nginx:
    image: nginx
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf
      - mautic-docroot:/var/www/html/docroot:z
    depends_on:
      - mautic_web
    ports:
      - 8002:80
    networks:
      - default

  mautic_web:
    image: mautic/mautic:5-fpm
    links:
      - db:mysql
    volumes: *mautic-volumes

    environment:
      - DOCKER_MAUTIC_LOAD_TEST_DATA=${DOCKER_MAUTIC_LOAD_TEST_DATA}
      - DOCKER_MAUTIC_RUN_MIGRATIONS=${DOCKER_MAUTIC_RUN_MIGRATIONS}
    env_file:
      - .mautic_env
    healthcheck:
      test: cgi-fcgi -bind -connect 127.0.0.1:9000
      start_period: 5s
      interval: 5s
      timeout: 5s
      retries: 100
    depends_on:
      db:
        condition: service_healthy
    networks:
      - default

  mautic_cron:
    image: mautic/mautic:5-fpm
    links:
      - db:mysql
    volumes: *mautic-volumes
    environment:
      - DOCKER_MAUTIC_ROLE=mautic_cron
    env_file:
      - .mautic_env
    depends_on:
      mautic_web:
        condition: service_healthy
    networks:
      - default

  mautic_worker:
    image: mautic/mautic:5-fpm
    links:
      - db:mysql
    volumes: *mautic-volumes
    environment:
      - DOCKER_MAUTIC_ROLE=mautic_worker
    env_file:
      - .mautic_env
    depends_on:
      mautic_web:
        condition: service_healthy
    networks:
      - default

volumes:
  mysql-data:
  mautic-docroot:

networks:
  default:
    name: ${COMPOSE_PROJECT_NAME}-docker

```

---

<div class="post-metadata">

**Author:** ![imog](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/imog/32/3813_2.png) [@imog](https://forum.mautic.org/u/imog)\
**Post date:** [January 12, 2025, 3:08pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/9 "2025-01-12T15:08:22Z")

</div>

But now it looks different than before. Post result of

```auto
docker ps

```

and

```auto
docker logs db
docker logs mautic_web

```

please.  
Also exec into db Container and try mysql login there using the ‘root’ user and password.  
If that works, post the output of

```auto
show grants;

```

---

<div class="post-metadata">

**Author:** ![3von](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/3von/32/13516_2.png) [@3von](https://forum.mautic.org/u/3von)\
**Post date:** [January 12, 2025, 6:54pm UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/10 "2025-01-12T18:54:21Z")

</div>

docker ps

```auto
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1337c894fede nginx "/docker-entrypoint.…" 4 hours ago Up 4 hours 0.0.0.0:8002->80/tcp, [::]:8002->80/tcp farm-mail-nginx-1
ae32457b6411 mautic/mautic:5-fpm "/entrypoint.sh php-…" 4 hours ago Up 4 hours (unhealthy) 9000/tcp farm-mail-mautic_web-1
9c74d3761eaa mysql:8.0 "docker-entrypoint.s…" 4 hours ago Up 4 hours (healthy) 3306/tcp, 33060/tcp farm-mail-db-1

```

docker logs mautic\_web

```auto
mysqladmin: connect to server at 'db.farm-mail-docker' failed
error: 'Host '172.18.0.3' is not allowed to connect to this MySQL server'
mysqladmin: connect to server at 'db.farm-mail-docker' failed
error: 'Host '172.18.0.3' is not allowed to connect to this MySQL server'

```

Can’t login to mysql

```auto
oot@ae32457b6411:/var/www/html/docroot# mysql -hdb.farm-mail-docker -u root -p fmq2108b
Enter password:
ERROR 1130 (HY000): Host '172.18.0.3' is not allowed to connect to this MySQL server
root@ae32457b6411:/var/www/html/docroot# mysql
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)

```

---

<div class="post-metadata">

**Author:** ![3von](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/3von/32/13516_2.png) [@3von](https://forum.mautic.org/u/3von)\
**Post date:** [January 19, 2025, 7:26am UTC](https://forum.mautic.org/t/docker-installation-cant-connect-to-mysql-server/34710/11 "2025-01-19T07:26:06Z")

</div>

I gave up on this and managed to get it installed with composer.
