Github Actions - Can't connect to mysql

Hi All,

I am trying to connect to the mysql database from ly pipeline, but its giving error. Although it used to work.

Part of my pipeline.yml

jobs:
  build-and-publish:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: Set up JDK 11
      uses: actions/setup-java@v1
      with:
        java-version: 11
    - name: Create test database
      run: |
        mysql -uroot -proot < databases/tracker/create_databases.sql
        ./gradlew testMigrate
    - name: Build with Gradle
      run: ./gradlew build
    - name: Publish artifact
      uses: actions/upload-artifact@v1

Error message:

Run mysql -uroot -proot < databases/tracker/create_databases.sql
  mysql -uroot -proot < databases/tracker/create_databases.sql
  ./gradlew testMigrate
  shell: /bin/bash -e {0}
  env:
    JAVA_HOME: /opt/hostedtoolcache/jdk/11.0.6/x64
    JAVA_HOME_11.0.6_x64: /opt/hostedtoolcache/jdk/11.0.6/x64
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
##[error]Process completed with exit code 1.

I have tried with 

mysql -h127.0.0.1 -uroot -proot < databases/tracker/create_databases.sql

Error message:

Create test database4s
##[error]Process completed with exit code 1.
Run mysql -uroot -proot -h127.0.0.1 < databases/tracker/create_databases.sql
  mysql -uroot -proot -h127.0.0.1 < databases/tracker/create_databases.sql
  ./gradlew testMigrate
  shell: /bin/bash -e {0}
  env:
    JAVA_HOME: /opt/hostedtoolcache/jdk/11.0.6/x64
    JAVA_HOME_11.0.6_x64: /opt/hostedtoolcache/jdk/11.0.6/x64
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
##[error]Process completed with exit code 1.
 Build with Gradle

Can anyone help. Has anything changed? Am I doing anything wrong?

Thanks,

Sid

2 Likes

I’m having this issue too. I think the ubuntu-latest image might have changed?

The issue is caused by this change: https://github.blog/changelog/2020-02-21-github-actions-breaking-change-ubuntu-virtual-environments-will-no-longer-start-the-mysql-service-automatically/

You could start mysql before creating database:  

- name: Create test database
   run: |
**sudo systemctl start mysql** mysql -uroot -proot < databases/tracker/create_databases.sql
10 Likes