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
- create data base
mysql
dump - 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 Answer 1
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
-
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– danblack2022年02月03日 22:27:02 +00:00Commented Feb 3, 2022 at 22:27
~/apps/mariadb/dump:/docker-entrypoint-initdb.d
containing themysqldump
ofcitizix_db
as a.sql
file in thedump
directory.