MySQL init script on Docker compose

Vicky AV
1 min readSep 25, 2020
Image from https://codingrabbithole.com/set-up-mysql-in-docker-with-docker-compose/

MySQL Docker container supports executing init scripts on startup

All we need to do is either copy or mount our script files to /docker-entrypoint-initdb.d/ folder inside MySQL docker image

docker-compose.yaml

Things to note

We have renamed the schema.sql & data.sql files as 1.sql & 2.sql respectively on mounting (refer line no 11 & 12). This was done for a reason.

MySQL docker container executes script files from /docker-entrypoint-initdb.d/ folder in the ascending order of file names

E.g. In case we have data.sql & schema.sql, data.sql will be executed first before schema.sql file

If you want more control over the script file’s execution order, please rename the files with numbers in ascending order (refer line no 11 & 12)

--

--