Skip to content

MariaDB container setup

Introduction

MariaDB is a fork of the MySQL database. I use this database, among other things, to store data from Home Assistant. Furthermore, it is very easy to connect MariaDB to Grafana to visualize data.

Setup

Below are the steps you can follow for the Linux terminal or NixOS configuration.

  1. Create the folders needed by the container

    Run the following commands inside your home folder:

    # Open your terminal application
    cd ~
    mkdir -p mariadb/data
    mkdir -p mariadb/config
    cd mariadb
  2. Create the script needed to run the container

    Save the following script as mariadb_run.sh:

    mariadb_run.sh
    # To create this script use your text editor application, for example Nano
    docker run -d \
    --hostname=mariadb \
    --name=mariadb \
    --net=host \
    -v $PWD/config:/etc/mysql/conf.d \
    -v $PWD/data:/var/lib/mysql \
    -e MYSQL_ROOT_PASSWORD=<password> \
    -e TZ="Europe/Amsterdam" \
    --restart=unless-stopped \
    mariadb
    # IMPORTANT: Please read the instructions below
    Instructions:
    • Optional Replace docker with podman if needed
    • Optional Replace --net=host with ports to pass through if you want to expose ports. Here is described how to check if ports are available
    • Optional Replace $PWD/config with the location of your config if needed. This can be a fileserver mount
    • Optional Replace $PWD/data with the location of your data if needed. This can be a fileserver mount
    • Required Replace <password> with your own password
    • Required Replace Europe/Amsterdam with your own timezone
  3. Run the script to create the container

    Run the following command:

    # Open your terminal application
    sudo sh mariadb_run.sh

    The image mariadb is automatically pulled and the container is created.

  4. Check the results

    If needed you can check if the container is running properly.

    To handle the administration of MariaDB I personally use phpMyAdmin.

Favorites

Comments

    No comments found for this note.

    Join the discussion for this note on Github. Comments appear on this page instantly.

    Copyright 2021- Fiction Becomes Fact