2

I am running a local instance of

$ mysql --version
mysql  Ver 8.0.27-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

and would like to move the whole database into mariaDB docker container.

If I see it correctly I need two steps

  1. create data base mysql dump
  2. deploying the docker container and integrating the data dump

I still struggle with creating a database dump and how to add into the container. Usually I use something like this as a compose file

version: '3.3'
services:
    mariadb:
        container_name: my-mariadb
        ports:
            - '3306:3306'
        volumes:
            - '~/apps/mariadb/data:/var/lib/mysql'
        environment:
            - MYSQL_ROOT_PASSWORD=S3cret
            - MYSQL_PASSWORD=An0thrS3crt
            - MYSQL_USER=citizix_user
            - MYSQL_DATABASE=citizix_db
        image: 'mariadb:10.7'
1
  • Try using another volume ~/apps/mariadb/dump:/docker-entrypoint-initdb.d containing the mysqldump of citizix_db as a .sql file in the dump directory.
    – danblack
    Commented Feb 3, 2022 at 7:42

1 Answer 1

2

You need to map the dump file to a specific folder, so it will be used only once when the container is created(init bash scripts can be put in the same folder, to be executed once when the container is created):

volumes:
  - '~/apps/mariadb/data:/var/lib/mysql'
  - ./somepath/dump123.sql:/docker-entrypoint-initdb.d/dump.sql

Initializing a fresh instance

When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql, .sql.gz, .sql.xz and .sql.zst that are found in /docker-entrypoint-initdb.d. Files will be executed in alphabetical order. .sh files without file execute permission are sourced rather than executed. You can easily populate your mariadb services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by the MARIADB_DATABASE / MYSQL_DATABASE variable.

From here: https://hub.docker.com/_/mariadb

1
  • Key point is to restrict the mysqldump to a single database instance. MySQL-8.0 system tables definitely won't work with any MariaDB version. Even your single database needs to examine differences and incompatibilies and might require syntax changes. This can be aided with sqlines mysql to mariadb migration. Recommend testing with a --no-data mysqldump first.
    – danblack
    Commented Feb 3, 2022 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.