How to Spin Up a MariaDB Service for Tests in GitHub Actions
MariaDB ships its own healthcheck.sh probe, which is the most reliable readiness signal for a service container.
Use the official mariadb image as a service, set MARIADB_ROOT_PASSWORD and MARIADB_DATABASE, map port 3306, and probe readiness with the bundled healthcheck.sh.
Steps
- Add
services.mariadbwithimage: mariadb:11. - Set
MARIADB_ROOT_PASSWORDandMARIADB_DATABASE. - Use
healthcheck.sh --connect --innodb_initializedas the health command. - Connect over
127.0.0.1:3306with the MySQL-compatible client.
Workflow
.github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:11
env:
MARIADB_ROOT_PASSWORD: root
MARIADB_DATABASE: app_test
ports:
- 3306:3306
options: >-
--health-cmd "healthcheck.sh --connect --innodb_initialized"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DATABASE_URL: mysql://root:root@127.0.0.1:3306/app_test
steps:
- uses: actions/checkout@v4
- run: npm ci && npm testGotchas
- MariaDB env vars use the
MARIADB_prefix; the legacyMYSQL_prefix still works but is deprecated. - The bundled
healthcheck.sh --connect --innodb_initializedis more accurate than a baremysqladmin ping.
Related guides
How to Spin Up a MySQL Service for Tests in GitHub ActionsRun MySQL as a GitHub Actions service container with a mysqladmin ping health check and a connection string o…
How to Spin Up a Postgres Service for Tests in GitHub ActionsRun a real Postgres alongside your GitHub Actions tests using a service container with a pg_isready health ch…
How to Wait for a Database to Be Ready in GitHub ActionsMake GitHub Actions wait until a database accepts connections using service health checks or a pg_isready ret…