Skip to content

Instantly share code, notes, and snippets.

@MKagesawa
Created August 21, 2018 08:07
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save MKagesawa/a03892b8c44c015cd991c2c5311f1768 to your computer and use it in GitHub Desktop.
Save MKagesawa/a03892b8c44c015cd991c2c5311f1768 to your computer and use it in GitHub Desktop.
Docker-compose MySQL Image create multiple databases
# The official MySQL (https://hub.docker.com/_/mysql/) supports only one MYSQL_DATABASE environment variable.
# By modifying the entrypoint and passing shell script, you can create multiple dbs without having to make a mysql image just for this purpose.
version: '3'
services:
# Some other service connecting to mysql
db:
image: mysql:5.6
environment:
- MYSQL_USER=root
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
entrypoint:
sh -c "
echo 'CREATE DATABASE IF NOT EXISTS firstDB; CREATE DATABASE IF NOT EXISTS secondDB;' > /docker-entrypoint-initdb.d/init.sql;
/usr/local/bin/docker-entrypoint.sh --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
"
ports:
- 3306:3306
Copy link

ghost commented Dec 9, 2018

I have tried server options for creating multiple databases. This is the only one which worked . Great. Thank you so much!!

@manishkpr
Copy link

there is very well explained tutorial for the multiple databases found which works perfect
https://medium.com/@onexlab.io/docker-compose-mysql-multiple-database-fe640938e06b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment