Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Error, access denied for user 'root'@'localhost' (using password: YES) I am trying to use the mysql service in Github Actions, but to no luck. I get the following error

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

My job is the following:

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;'

I cant seem to get it to work. Any help is appreciated. The pull request for my repository for the test setup can be found here: https://github.com/morsby/medmcq/pull/399

like image 825
Thjen Avatar asked Oct 03 '19 15:10

Thjen


1 Answers

I spent some time trying different things to get this to work. I found a solution, but quite honestly, I'm not sure why it works. I simply added -h 127.0.0.1 to the mysql command.

I also added the health check flags to options to make sure the service is able to accept requests.

This is a working workflow:

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;'
like image 124
peterevans Avatar answered Oct 23 '22 04:10

peterevans