diff --git a/bitnami/mysql/5.7/debian-9/rootfs/entrypoint.sh b/bitnami/mysql/5.7/debian-9/rootfs/entrypoint.sh index 8be54823dc66..f3cdcae337ec 100755 --- a/bitnami/mysql/5.7/debian-9/rootfs/entrypoint.sh +++ b/bitnami/mysql/5.7/debian-9/rootfs/entrypoint.sh @@ -18,6 +18,7 @@ print_welcome_page if [[ "$*" = "/run.sh" ]]; then info "** Starting MySQL setup **" /setup.sh + touch "$DB_VOLUMEDIR"/.mysql_initialized info "** MySQL setup finished! **" fi diff --git a/bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh b/bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh index 8be54823dc66..f3cdcae337ec 100755 --- a/bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh +++ b/bitnami/mysql/5.7/ol-7/rootfs/entrypoint.sh @@ -18,6 +18,7 @@ print_welcome_page if [[ "$*" = "/run.sh" ]]; then info "** Starting MySQL setup **" /setup.sh + touch "$DB_VOLUMEDIR"/.mysql_initialized info "** MySQL setup finished! **" fi diff --git a/bitnami/mysql/8.0/debian-9/rootfs/entrypoint.sh b/bitnami/mysql/8.0/debian-9/rootfs/entrypoint.sh index 8be54823dc66..f3cdcae337ec 100755 --- a/bitnami/mysql/8.0/debian-9/rootfs/entrypoint.sh +++ b/bitnami/mysql/8.0/debian-9/rootfs/entrypoint.sh @@ -18,6 +18,7 @@ print_welcome_page if [[ "$*" = "/run.sh" ]]; then info "** Starting MySQL setup **" /setup.sh + touch "$DB_VOLUMEDIR"/.mysql_initialized info "** MySQL setup finished! **" fi diff --git a/bitnami/mysql/8.0/ol-7/rootfs/entrypoint.sh b/bitnami/mysql/8.0/ol-7/rootfs/entrypoint.sh index 8be54823dc66..f3cdcae337ec 100755 --- a/bitnami/mysql/8.0/ol-7/rootfs/entrypoint.sh +++ b/bitnami/mysql/8.0/ol-7/rootfs/entrypoint.sh @@ -18,6 +18,7 @@ print_welcome_page if [[ "$*" = "/run.sh" ]]; then info "** Starting MySQL setup **" /setup.sh + touch "$DB_VOLUMEDIR"/.mysql_initialized info "** MySQL setup finished! **" fi diff --git a/bitnami/mysql/README.md b/bitnami/mysql/README.md index 0f6bdee9a606..051992b28b8c 100644 --- a/bitnami/mysql/README.md +++ b/bitnami/mysql/README.md @@ -278,6 +278,19 @@ services: **Note!** The `root` user will be created with remote access and without a password if `ALLOW_EMPTY_PASSWORD` is enabled. Please provide the `MYSQL_ROOT_PASSWORD` env variable instead if you want to set a password for the `root` user. +## Ensuring the database is ready before connecting + +You should define a [health check](https://docs.docker.com/compose/compose-file/#healthcheck) via docker-compose.yml to ensure that MySQL has been fully initialized and is ready to accept connections before using the container. For example, if you have created a database and user as instructed above: + +```yaml +services: + mysql: + ... + healthcheck: + test: bash -c "[ -f /bitnami/mysql/.mysql_initialized ]" && mysql -uMYSQL_USER -pMYSQL_PASSWORD MYSQL_DATABASE --silent --execute "SHOW TABLES;" + ... +``` + ## Setting up a replication cluster A **zero downtime** MySQL master-slave [replication](https://dev.mysql.com/doc/refman/5.7/en/server-option-variable-reference.html) cluster can easily be setup with the Bitnami MySQL Docker image using the following environment variables: