How to migrate a mysql into a mariaDB docker container?



  • 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'
    

  • QA Engineer

    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




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2