I installed MySQL 9.0 in the docker environment using mirromutth/[email protected]
[1] in GitHub Action. I set it up in Spring project as follows.
File application.yml
spring:
datasource:
url: jdbc:mysql://localhost:3306/testdb?serverTimezone=UTC
username: root
password: 1234
jpa:
database-platform: org.hibernate.dialect.MySQLDialect
open-in-view: false
show-sql: true
properties:
hibernate:
format_sql: true
# hbm2ddl.auto: create
When I uncomment the annotation part from this code, it didn’t connect to mysql in github action. Why does that one line change the result?
[workflow]
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
permissions:
contents: read
uses: ./.github/workflows/build.yml
test:
permissions:
contents: read
uses: ./.github/workflows/test.yml
dependency-submission:
permissions:
contents: write
uses: ./.github/workflows/dependency-submission.yml
name: test
on:
workflow_call:
jobs:
test:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v4
- name: Set up MySQL
uses: mirromutth/[email protected]
with:
host port: 3306
container port: 3306
character set server: 'utf8mb4'
collation server: 'utf8mb4_general_ci'
mysql version: '9.0'
mysql database: 'testdb'
mysql user: 'root'
mysql password: '1234'
- name: Get MySQL container ID
run: echo "::set-output name=container_id::$(docker ps -q -f ancestor=mysql:9.0)"
id: container_id
- name: Print MySQL version
run: |
docker exec -i ${{ steps.container_id.outputs.container_id }}
mysql -uroot -p1234 -e "SELECT VERSION();"
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
- name: test with Gradle Wrapper
run: ./gradlew test -s
When I tried to connect with Unix socket, I got the error message like
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.
When I set IP as a 127.0.0.1 and tried to connect with TCP/IP, I got the error message like ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
When I set IP as a localhost and tried to connect with TCP/IP, I got the error message like ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (111)
And I waited for a long time using mysqladmin ping
but it was not connected.
MySQL container was running, and ip:port had no problem. The database name also matches. I tried all the other methods (TCP connection, permission setting, socket path check, etc.) but it didn’t work. Just that comment alone will change the outcome of the run. I’ve seen the following but I haven’t got a solution.
How to connect to MySQL databas using GitHub Actions?
Installing MySQL in Docker fails with error message “Can’t connect to local MySQL server through socket”
Any help or offer would be appreciated.
[1] https://github.com/mirromutth/mysql-action
2