mirromutth/mysql-action

MySQL server has gone away

Opened this issue ยท 8 comments

I get this error from time to time:

SQLSTATE[HY000] [2006] MySQL server has gone away

I just re-run the job multiple times until it works.
This is my conf for MySQL setup:

- name: Setup MySQL
        uses: mirromutth/mysql-action@v1.1
        with:
          mysql database: test
          mysql user: test
          mysql password: test

I got the same error when switching from mysql 5.7 to 8.0. Reverting back to 5.7 fixed the issue. @mehdibo did you find a solution to the problem other than reverting back to 5.7?

No, I always had the issue, it would work for sometime and then randomly stops working.

I eventually switched to Travis Ci.

Try building your own docker container, I remember using Github Actions with docker-compose that had a db container and it worked fine.

Adding a sleep 15 command to wait for the mysql server to become available fixed this issue for me

- name: Wait for MySQL
  run: sleep 15

I agree with @almasaeed2010

When i had to make a pipeline for GitLab CI i use the following code before my test execution because sometimes the MySQL service fails.

# Ensure that mysql server is up and running
ping -c 3 mysql

But sleep 15 will lock the docker instance for sure. Adding static cost for the CI process, a better solution than retry the execution hoping that works as a magic trick.

After a lot of time with inconsistent errors, I did this:

(...)
env:
      MYSQL_ROOT_PASSWORD: password
          
    steps:
      (...) first steps, but the sooner you call MySQL, the better
      
      - name: Setup MySQL
        uses: mirromutth/mysql-action@v1.1
        with:
          mysql root password: $MYSQL_ROOT_PASSWORD

      (...) all other things that don't need MySQL

      - name: Wait for MySQL
        run: |
          while ! mysqladmin ping --host=127.0.0.1 --password=$MYSQL_ROOT_PASSWORD --silent; do
            sleep 1
          done

      (...) steps where you need MySQL

If you think it is a good approach, I don't have a problem adding this note in the README file (and doing a PR) so new users don't waste time.

better add some timeout as well @NBajanca

That should definitely added to README.txt to avoid waste of time.

rodber commented

You may need to add this option:

-P 3800 

If you are using:

host port: 3800