Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Multiple Databases without init script #338

Closed
scrummyin opened this issue Oct 26, 2017 · 8 comments
Closed

Creating Multiple Databases without init script #338

scrummyin opened this issue Oct 26, 2017 · 8 comments

Comments

@scrummyin
Copy link

I found a bug/feature. I was able to create multiple databases without the need for my own dockerfile. I kinda abused the docker-entrypoint.sh. Below is a terminal session that shows how I did it

$ cat elist
MYSQL_DATABASE=one`; CREATE DATABASE IF NOT EXISTS two; CREATE DATABASE IF NOT EXISTS `three
MYSQL_ROOT_PASSWORD=pass
$ docker run -p 127.0.0.1:3306:3306 --env-file elist mysql

I'm not sure want to do with this information, but it works as a quick hack to get multiple databases.

@tianon
Copy link
Member

tianon commented Nov 15, 2017

Heh, this is a cute hack -- I'm not sure what to do with it either. Either leave it as an easter egg or try to do some form of mysql_real_escape_string in Bash? (yuck)

I'm inclined to simply leave it as an undocumented thing that happens to work as a consequence of how our script works and leave it alone (since we'd likely have to add more dependencies and thus make the image bigger to attempt to "fix" it properly and having backtick in a database name should be pretty rare and those folks should have to think long and hard about what the heck they're doing).

@tianon
Copy link
Member

tianon commented Apr 19, 2018

Since this isn't something we've deemed worth fixing, I'm going to close -- the issue will hopefully serve as a good enough reference for folks looking to take advantage of this accidental "feature" (which is really a bug, to be explicitly clear). 👍

@tianon tianon closed this as completed Apr 19, 2018
@seekcx
Copy link

seekcx commented May 3, 2018

  • Multiple database support.

Awesome!
This is exactly what I want.

@dmitrym0
Copy link

This is cute, but surely there's a cleaner way to create multiple database on init? What about permission grants?

@tianon
Copy link
Member

tianon commented May 10, 2018

The cleaner way is to use a proper SQL file (or shell script) in /docker-entrypoint-initdb.d that performs the steps necessary to set up the database in the way that you need.

@xandriaw
Copy link

@tianon can I just have two .sql scripts, each with 'create database' commands in them or is there something more necessary?

@tianon
Copy link
Member

tianon commented May 15, 2018 via email

@glensc
Copy link
Contributor

glensc commented Oct 2, 2018

Bobby Tables

:D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants