Skip to content
Latchkey

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.mariadb with image: mariadb:11.
  • Set MARIADB_ROOT_PASSWORD and MARIADB_DATABASE.
  • Use healthcheck.sh --connect --innodb_initialized as the health command.
  • Connect over 127.0.0.1:3306 with 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 test

Gotchas

  • MariaDB env vars use the MARIADB_ prefix; the legacy MYSQL_ prefix still works but is deprecated.
  • The bundled healthcheck.sh --connect --innodb_initialized is more accurate than a bare mysqladmin ping.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →