Docker Community Forums

Share and learn in the Docker community.

How best to populate a MySQL database?


#1

Hello,

I have a MySQL database I’ve got running in a container as part of a docker-compose file with a REST service. What I’m wondering is how best to populate that database since it’s just an empty MySQL default instance.

Since I have a REST service running in another container, maybe populating the database programmatically from the service would be the best route?

Looking for suggestions from the community here. :slight_smile:

Thanks for any suggestions.


(Martin Terp) #2
    volumes:
      - ./dump.sql:/docker-entrypoint-initdb.d/dump.sql

The image runs every SQL file in that dir, at creation point :slight_smile:


#3

Thank you very much. This worked perfectly. :slight_smile:


(Ove "Lime" Lindström) #4

A note: it is going to run it in alphanumeric order. I recommend that you prefix the sql files with a number, for example like this:
1_Create_Database.sql
2_Create_Tables.sql
3_PopulateTestData.sql

and so on.


#5

Thanks for that information. I’ll do that.