How to pass "mysql_native_password" to MySQL service in GitHub Actions?

Viewed 5414

Example of my GitHub Action config:

jobs:
  unit-test:
    name: Unit Testing
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:8.0
        env:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: db
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
    steps:
      - name: Verify MySQL connection from host
        run: mysql --host mysql --port 3306 -uroot -ppassword -e "SHOW DATABASES"

With MySQL 5.7 it works. But with MySQL 8.0 it shows:

ERROR 1045 (28000): Plugin caching_sha2_password could not be loaded: ...

In MySQL docker docs there is a line which allows mysql_native_password auth:

command: --default-authentication-plugin=mysql_native_password

How to allow the mysql_native_password auth plugin in GitHub Actions/service?

2 Answers

The issue is that GH actions does not move --entrypoint option and related arguments to the end of the command but instead it appends other options like env. variables specified in env service section after it.

After a lot of trial and errors I found out, you can specify the env. vars manually, command like this is working:

...
    services:
      mysql:
        image: mysql:8
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=xxx -e MYSQL_USER=xxx -e MYSQL_PASSWORD=xxx -e MYSQL_DATABASE=xxx --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
    steps:
...

Currently its not possible to specify command option in github actions service workflow syntax, a simpler alternative is to use a different mysql image and override the entrypoint to use native password, or use an existing image that provides configuring auth method using env variables like this bitnami mysql image.

Using the bitnami mysql image:

    services:
      mysql:
        image: bitnami/mysql:8.0.20
        env:
          ALLOW_EMPTY_PASSWORD: yes
          MYSQL_DATABASE: abc
          MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
        ports:
          - 3306/tcp
        options: >-
          --health-cmd="mysqladmin ping" 
          --health-interval=10s 
          --health-timeout=5s 
          --health-retries=3
Related