Github 操作:使用 mysql 服务抛出拒绝用户 'root'@'localhost' 的访问

Github actions: Using mysql service throws access denied for user 'root'@'localhost'

错误,用户 'root'@'localhost' 的访问被拒绝(使用密码:YES) 我正在尝试在 Github 操作中使用 mysql 服务,但没有成功。我收到以下错误

Access denied for user 'root'@'localhost' (using password: YES)

我的工作如下:

test:
  name: Test
  needs: install
  services:
    mysql:
      image: mysql:8.0
      ports:
        - '8888:3306'
      env:
        MYSQL_ROOT_PASSWORD: rootpass
        MYSQL_DATABASE: test
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@master
    - uses: actions/setup-node@master
      with:
        node-version: '10.x'
    - run: mysql --port 8888 -u root -prootpass -e 'CREATE DATABASE IF NOT EXISTS test;'

我似乎无法让它工作。任何帮助表示赞赏。可以在此处找到我的测试设置存储库的拉取请求:https://github.com/morsby/medmcq/pull/399

我花了一些时间尝试不同的方法来让它工作。我找到了解决方案,但老实说,我不确定 为什么 它有效。我只是将 -h 127.0.0.1 添加到 mysql 命令。

我还向 options 添加了健康检查标志,以确保该服务能够接受请求。

这是一个工作流程:

name: CI
on: push
jobs:
  build:
    runs-on: ubuntu-latest
    services:
      mysql:
        image: mysql:8.0
        env:
          MYSQL_ROOT_PASSWORD: password
          MYSQL_DATABASE: test
        ports:
            - '8888:3306'
        options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
    steps:
      - uses: actions/checkout@v1
      - run: mysql -h 127.0.0.1 --port 8888 -u root -ppassword -e 'CREATE DATABASE IF NOT EXISTS test;'