wodby / mariadb

MariaDB docker container image
https://wodby.com/stacks/mariadb
GNU General Public License v2.0
49 stars 31 forks source link

How to execute a query on startup with actions.mk? #23

Closed vstanchev closed 3 years ago

vstanchev commented 5 years ago

I want to create a second database on the same container (for tests). I see that there is an actions.mk file with some query actions which I can call in an init script located at /docker-entrypoint-init.d/. However, I always get the error /usr/local/bin/actions.mk:32: *** Required parameter is missing: query. Stop.

I tried entering the container and executing a query from there but it's the same error.

$ docker-compose exec mariadb bash
/var/lib/mysql$ make -f /usr/local/bin/actions.mk query "SHOW DATABASES;"
/usr/local/bin/actions.mk:32: *** Required parameter is missing: query.  Stop.

What I'm doing wrong? Should the query be passed in another way?

I'm using the 10.3-3.4.11 image.

vstanchev commented 5 years ago

As a workaround I added the following script to the /docker-entrypoint-initdb.d/ (apparently /docker-entrypoint-init.d/ is not used in the mariadb image as opposed to all other alpine images, I guess this is because the server needs to be started before init scripts?)

#!/usr/bin/env bash
set -e
TEST_DATABASE="${MYSQL_DATABASE}_test"
mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" -e "CREATE DATABASE IF NOT EXISTS ${TEST_DATABASE}"
mysql -uroot -p"${MYSQL_ROOT_PASSWORD}" -e "GRANT ALL ON \`${TEST_DATABASE}\`.* TO '${MYSQL_USER}'@'%'"
csandanov commented 5 years ago

Params for make commands described at https://github.com/wodby/mariadb#orchestration-actions