# API 502 error as soon as I added mysql database credentials

**URL:** <https://community.vikunja.io/t/api-502-error-as-soon-as-i-added-mysql-database-credentials/376>\
**Category:** Support\
**Created:** [29 September 2021 13:17 UTC](https://community.vikunja.io/t/api-502-error-as-soon-as-i-added-mysql-database-credentials/376 "2021-09-29T13:17:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zoker](https://community.vikunja.io/user_avatar/community.vikunja.io/zoker/32/191_2.png) [@Zoker](https://community.vikunja.io/u/Zoker)\
**Post date:** [29 September 2021 13:17 UTC](https://community.vikunja.io/t/api-502-error-as-soon-as-i-added-mysql-database-credentials/376/1 "2021-09-29T13:17:23Z")

</div>

Hi there,

Until now I had vikunja running with a sqlite Database. But since this is to unsecure for me (loosing data by deleting the file etc.) I wanted to switch to mysql.

So I added the following lines to my docker compose file:

```auto
      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_HOST: 1.1.1.1
      VIKUNJA_DATABASE_DATABASE: vikunja
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_PASSWORD: vikunja

```

So my compose file now looks like this:

```auto
version: '3.8'
services:
  api:
    image: vikunja/api
    container_name: API
    restart: always
    volumes:
      - ~/docker/vikunja/files:/app/vikunja/files
    environment:
      VIKUNJA_SERVICE_ENABLECALDAV: 'false'
      VIKUNJA_SERVICE_ENABLEREGISTRATION: 'false'
      VIKUNJA_SERVICE_ENABLEUSERDELETION: 'false'
      VIKUNJA_SERVICE_TIMEZONE: 'Europe/Berlin'
      VIKUNJA_DATABASE_TYPE: mysql
      VIKUNJA_DATABASE_HOST: 1.1.1.1
      VIKUNJA_DATABASE_DATABASE: vikunja
      VIKUNJA_DATABASE_USER: vikunja
      VIKUNJA_DATABASE_PASSWORD: vikunja
  frontend:
    image: vikunja/frontend
    container_name: Frontend
    restart: always
  proxy:
    image: nginx
    container_name: Proxy
    restart: always
    ports:
      - 80:80/tcp
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    depends_on:
      - api
      - frontend

```

The DB is hosted on an external server, so I entered my IP address for the host env (like `VIKUNJA_DATABASE_HOST: 1.1.1.1` (of course I changed this to my servers IP)

When I then start the container, the API endpoint is not available anymore. I always get a 502 Bad Gateway, when I try to access `<ip>/api/v1/info` and login/register is also not possible anymore.

When I remove the db lines again, everything works fine again.  
I also checked the API container logs, and this is the only content:

```auto
usermod: no changes
2021/09/29 13:10:21 Config File "config" Not Found in "[/app/vikunja /etc/vikunja /app/vikunja/.config/vikunja]"
2021/09/29 13:10:21 Using default config.

```

Do I miss something within the config? What can I do to fix this?

Thanks!

---

<div class="post-metadata">

**Author:** ![kolaente](https://community.vikunja.io/user_avatar/community.vikunja.io/kolaente/32/5_2.png) [@kolaente](https://community.vikunja.io/u/kolaente)\
**Post date:** [29 September 2021 19:17 UTC](https://community.vikunja.io/t/api-502-error-as-soon-as-i-added-mysql-database-credentials/376/2 "2021-09-29T19:17:38Z")

</div>

Hi 👋

There should be other lines like

```auto
2021-09-29T21:14:03.532999671+02:00: INFO	▶ cmd/func2 04a Vikunja version v0.18.1+22-2ab27c72f2
⇨ http server started on [::]:3456

```

If these are missing that could indicate a problem _somewhere_. Can you verify the container can reach the mysql container?

The 502 seems to indicate the proxy cannot reach the api container - can you verify that as well? It should be running and reachable under the path you have in your `nginx.conf` file.

---

<div class="post-metadata">

**Author:** ![Zoker](https://community.vikunja.io/user_avatar/community.vikunja.io/zoker/32/191_2.png) [@Zoker](https://community.vikunja.io/u/Zoker)\
**Post date:** [29 September 2021 23:33 UTC](https://community.vikunja.io/t/api-502-error-as-soon-as-i-added-mysql-database-credentials/376/3 "2021-09-29T23:33:07Z")

</div>

Hi,

A firewall rule bocked the connection to the database server 🙄  
But thanks for the help! 🙂
