Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 933
mvorisek Avatar asked Mar 28 '20 15:03

mvorisek


People also ask

What is MySQL mysql_native_password?

The mysql_native_password authentication plugin is the default authentication plugin that will be used for an account created when no authentication plugin is explicitly mentioned and old_passwords=0 is set.

Is mysql_native_password secure?

Basically, mysql_native_password is the traditional method to authenticate- it is not very secure (it uses just a hash of the password), but it is compatible with older drivers. If you are going to start a new mysql service, you probably want to use the new plugin from the start (and TLS).

Can I run a MySQL server on Ubuntu?

The Ubuntu image already contains a preconfigured MySQL server but if you want to use a specific or newer version or even a MariaDB server you need to use a service. A service in Github Actions is just a docker container running a specific image and exposing it’s ports to localhost.

Does MySQL action work on Mac OS and Windows?

It is based on the Docker container and is limited by Github Actions, which contains only Linux now. Therefore it does not work in Mac OS and Windows environment. steps : - uses: mirromutth/[email protected] with : host port: 3800 # Optional, default value is 3306.

Why can’t I connect to a MySQL container on my server?

It most likely means that a host ( ubuntu-20.04) can’t connect to a separate MySQL container that is created using your services:mysql details due to ports issues. Ever wondered why there are official PostgreSQL and Redis services guides available for you on docs.github.com, but not for MySQL?

Is it possible to run MySQL inside a workflow?

If you come to this post from a Google search, you may have already read a ton of tutorials that have this code running MySQL inside your workflow: Some may have included additional information on why do you need env inside the MySQL service, some may not.


1 Answers

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
like image 62
Aszen Avatar answered Sep 17 '22 12:09

Aszen