# Database not persistent

**URL:** <https://forums.balena.io/t/database-not-persistent/131690>\
**Category:** balenaOS\
**Created:** [June 12, 2020, 8:21am UTC](https://forums.balena.io/t/database-not-persistent/131690 "2020-06-12T08:21:39Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kerstin\_boergers](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kerstin\_boergers](https://forums.balena.io/u/kerstin_boergers)\
**Post date:** [June 12, 2020, 8:21am UTC](https://forums.balena.io/t/database-not-persistent/131690/1 "2020-06-12T08:21:39Z")

</div>

Hi!  
I’ve got a problem with persistent data on a multi-container app on a revolution pi 3 (balenaOS 2.31.5+rev2):  
On restarting the webmacs.mariadb container the database is deleted, even after following the docs [https://www.balena.io/docs/learn/develop/runtime/](https://www.balena.io/docs/learn/develop/runtime/)  
Do you have an idea what’s going wrong?

docker-compose file:  
version: ‘2.1’

```
volumes:
  webmacs-data:

services:
#################################
# Setup webmacs.mysql container #
#################################
  webmacs.mariadb:
    container_name: webmacs.mariadb
    hostname: webmacs.mariadb
    image: webhippie/mariadb:latest
    ports:
      - 3306:3306
    volumes:
      - 'webmacs-data:/data'
    privileged: true
    build:
      context: ./webmacs.mysql
      dockerfile: Dockerfile
    environment:
      MYSQL_ROOT_PASSWORD: ####
      MYSQL_DATABASE: wirbelschicht_db
      MYSQL_USER: wirbelschicht
      MYSQL_PASSWORD: ####
      INSTALL_SAKILA: 1
      TZ: Europe/London

############################################
# Setup webmacs.phpmyadmin container #
############################################
  webmacs.phpmyadmin:
    container_name: webmacs.phpmyadmin
    hostname: webmacs.phpmyadmin
    image: jackgruber/phpmyadmin:armhf
    links:
      - webmacs.mariadb
    ports:
      - 80:80
    environment:
      PMA_HOST: webmacs.mariadb
      MYSQL_ROOT_PASSWORD: ####
    depends_on: 
      - webmacs.mariadb
```

---

<div class="post-metadata">

**Author:** ![bversluijs](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/bversluijs/32/3954_2.png) [@bversluijs](https://forums.balena.io/u/bversluijs)\
**Post date:** [June 12, 2020, 8:51am UTC](https://forums.balena.io/t/database-not-persistent/131690/2 "2020-06-12T08:51:19Z")

</div>

Hi,

If I’m correct, the location of the mariadb data is located in `/var/lib/mysql`. You’ve created a volume named `webmacs-data`, and set it in your `webmacs.mariadb` container, but it’s linked to `/data` with the following row:

```auto
volumes:
  - 'webmacs-data:/data'

```

But because the data of mariadb is stored in `/var/lib/mysql`, you’ve to change it accordingly:

```auto
volumes:
  - 'webmacs-data:/var/lib/mysql'

```

Now the volume in the container is linked to `/var/lib/mysql`, and the data should be persistent 🙂

---

<div class="post-metadata">

**Author:** ![kerstin\_boergers](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kerstin\_boergers](https://forums.balena.io/u/kerstin_boergers)\
**Post date:** [June 23, 2020, 1:51pm UTC](https://forums.balena.io/t/database-not-persistent/131690/4 "2020-06-23T13:51:32Z")

</div>

Thank you for the answer! I tried it out but it still doesn’t work 😅

---

<div class="post-metadata">

**Author:** ![JSReds](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/jsreds/32/2929_2.png) [@JSReds](https://forums.balena.io/u/JSReds)\
**Post date:** [June 23, 2020, 2:00pm UTC](https://forums.balena.io/t/database-not-persistent/131690/5 "2020-06-23T14:00:56Z")

</div>

Hi there,  
have you already tried to take a look at this guide: [https://hub.docker.com/r/bitnami/mariadb/](https://hub.docker.com/r/bitnami/mariadb/) chapter `Persisting your database` ?

---

<div class="post-metadata">

**Author:** ![kerstin\_boergers](https://avatars.discourse-cdn.com/v4/letter/k/e47c2d/32.png) [@kerstin\_boergers](https://forums.balena.io/u/kerstin_boergers)\
**Post date:** [June 23, 2020, 2:18pm UTC](https://forums.balena.io/t/database-not-persistent/131690/7 "2020-06-23T14:18:58Z")

</div>

Solved the problem. The data directory for mariadb was set to /config/databases instead of /var/lib/mysql.

It works with /config/databases now, thanks for the help! 🙂
