MySQL init script on Docker compose

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)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store