p238049y / junit-try

springbootでjunitの環境を構築しテストコードについて勉強する
0 stars 0 forks source link

【調査準備】MySQLの環境を構築し、通信できるようにする #7

Open p238049y opened 2 months ago

p238049y commented 2 months ago

https://github.com/p238049y/article-repository/issues/12 を書くための材料集め

方針としては

p238049y commented 2 months ago

参考:https://zenn.dev/ryo7/articles/create-mysql-on-docker

p238049y commented 2 months ago
❯❯❯ docker compose up                  ✘ 127 
[+] Running 12/12
 ✔ mysql 11 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                                159.3s 
   ✔ 5e407bf3af90 Pull complete                                                        150.3s 
   ✔ bbcaa884ef4a Pull complete                                                          1.3s 
   ✔ c0ba5caab336 Pull complete                                                          2.7s 
   ✔ e1ac943225fe Pull complete                                                         37.1s 
   ✔ 143875155e8f Pull complete                                                          6.6s 
   ✔ 78accec1f909 Pull complete                                                         11.1s 
   ✔ 0074132ff84a Pull complete                                                        102.0s 
   ✔ a92d978133e0 Pull complete                                                         38.5s 
   ✔ af33c7bb2ccb Pull complete                                                        116.8s 
   ✔ 446b165975c9 Pull complete                                                        103.0s 
   ✔ e06f8455314d Pull complete                                                        104.0s 
[+] Running 2/2
 ✔ Network mysql-docker_default  Created                                                 0.0s 
 ✔ Container mysql-container     Created                                                 0.6s 
Attaching to mysql-container
mysql-container  | 2024-09-14 17:51:30+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.39-1.el9 started.
mysql-container  | 2024-09-14 17:51:31+09:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
mysql-container  | 2024-09-14 17:51:31+09:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.39-1.el9 started.
mysql-container  | 2024-09-14 17:51:32+09:00 [Note] [Entrypoint]: Initializing database files
mysql-container  | 2024-09-14T08:51:32.264778Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql-container  | 2024-09-14T08:51:32.265818Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.39) initializing of server in progress as process 352
mysql-container  | 2024-09-14T08:51:32.298289Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql-container  | 2024-09-14T08:51:32.463513Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql-container  | 2024-09-14T08:51:33.580939Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
mysql-container  | 2024-09-14 17:51:35+09:00 [Note] [Entrypoint]: Database files initialized
mysql-container  | 2024-09-14 17:51:35+09:00 [Note] [Entrypoint]: Starting temporary server
mysql-container  | 2024-09-14T08:51:35.600203Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql-container  | 2024-09-14T08:51:35.603476Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.39) starting as process 411
mysql-container  | 2024-09-14T08:51:35.705582Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql-container  | 2024-09-14T08:51:35.887540Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql-container  | 2024-09-14T08:51:36.293035Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql-container  | 2024-09-14T08:51:36.293117Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql-container  | 2024-09-14T08:51:36.297462Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql-container  | 2024-09-14T08:51:36.325533Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
mysql-container  | 2024-09-14T08:51:36.325891Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.39'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
mysql-container  | 2024-09-14 17:51:36+09:00 [Note] [Entrypoint]: Temporary server started.
mysql-container  | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'
mysql-container  | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
mysql-container  | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
mysql-container  | Warning: Unable to load '/usr/share/zoneinfo/leapseconds' as time zone. Skipping it.
mysql-container  | Warning: Unable to load '/usr/share/zoneinfo/tzdata.zi' as time zone. Skipping it.
mysql-container  | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
mysql-container  | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
mysql-container  | 2024-09-14 17:51:37+09:00 [Note] [Entrypoint]: Creating database app-gis
mysql-container  | 
mysql-container  | 2024-09-14 17:51:37+09:00 [Note] [Entrypoint]: Stopping temporary server
mysql-container  | 2024-09-14T08:51:37.712268Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down mysqld (Version: 8.0.39).
mysql-container  | 2024-09-14T08:51:38.610350Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.39)  MySQL Community Server - GPL.
mysql-container  | 2024-09-14 17:51:38+09:00 [Note] [Entrypoint]: Temporary server stopped
mysql-container  | 
mysql-container  | 2024-09-14 17:51:38+09:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
mysql-container  | 
mysql-container  | 2024-09-14T08:51:38.951657Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
mysql-container  | 2024-09-14T08:51:38.954430Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.39) starting as process 1
mysql-container  | 2024-09-14T08:51:38.994502Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
mysql-container  | 2024-09-14T08:51:39.151648Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysql-container  | 2024-09-14T08:51:39.559181Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
mysql-container  | 2024-09-14T08:51:39.559288Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
mysql-container  | 2024-09-14T08:51:39.565051Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
mysql-container  | 2024-09-14T08:51:39.602828Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock
mysql-container  | 2024-09-14T08:51:39.602872Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.39'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server - GPL.

うまくいっていそう

p238049y commented 2 months ago
❯❯❯ docker ps
CONTAINER ID   IMAGE       COMMAND                   CREATED         STATUS         PORTS                               NAMES
3389441dc9e5   mysql:8.0   "docker-entrypoint.s…"   3 minutes ago   Up 3 minutes   0.0.0.0:3306->3306/tcp, 33060/tcp   mysql-container
p238049y commented 2 months ago
Caused by: org.flywaydb.core.api.FlywayException: Unsupported Database: MySQL 8.0
p238049y commented 2 months ago

build.gradleのパッケージのバージョンを変えることでエラーは解消された

次はコネクションできていなさそう


Caused by: org.flywaydb.core.internal.exception.FlywaySqlException: Unable to obtain connection from database: Unsupported character encoding 'utf8mb4'
p238049y commented 2 months ago
❯❯❯ ./gradlew clean build --refresh-dependencies

Welcome to Gradle 8.8!

Here are the highlights of this release:
 - Running Gradle on Java 22
 - Configurable Gradle daemon JVM
 - Improved IDE performance for large projects

For more details see https://docs.gradle.org/8.8/release-notes.html

> Task :test

JunitAppApplicationTests > contextLoads() FAILED
    java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:180
        Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1788
            Caused by: org.flywaydb.core.internal.exception.FlywaySqlException at JdbcUtils.java:60
                Caused by: java.sql.SQLException at SQLError.java:130
                    Caused by: com.mysql.cj.exceptions.WrongArgumentException at Constructor.java:502
                        Caused by: java.io.UnsupportedEncodingException at String.java:861

9 tests completed, 1 failed

> Task :test FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> There were failing tests. See the report at: file:///Users/nishimuraisamu/workspace/junit-app/build/reports/tests/test/index.html

* Try:
> Run with --scan to get full insights.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/8.8/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 51s
8 actionable tasks: 8 executed

失敗している