mutao.net

いわゆる雑記。

MySQL8系への移行に備える

MYSQL8系を使用するにはSpring で使われているMySQL Connector/Jをアップデートする必要があります。

今回はちょっと詰まってしまったところがあるのでメモ。

MySQLのEOL

https://www.oracle.com/us/support/library/lifetime-support-technology-069183.pdf

Oracle's MySQL Releasesに(p.28)記載がある通り5.7系は2023/10でEOLを迎える

まだ2年弱はあるものの、気づけばEOL...なんてことはどんなものでもあるのでなるはやで布石を打っておきたい。

MySQL Connector/J

pom / gradleの記載方法はmaven repositoryにあるのでここでは記載しない。

MySQL8系はConector/Jの8系を必要する必要がある。5.7系とも互換性があるので、Connector/Jだけまずはアップデートする戦略は結構あるあるらしい。

mvnrepository.com

github.com

DriverNameに設定するPATHが変更になっているので注意すること。

丁寧にlogも出してくれるようになっていた。

public class Driver extends com.mysql.cj.jdbc.Driver {
    public Driver() throws SQLException {
        super();
    }

    static {
        System.err.println("Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. "
                + "The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.");
    }
}
// https://github.com/mysql/mysql-connector-j/blob/18bbd5e68195d0da083cbd5bd0d05d76320df7cd/src/legacy/java/com/mysql/jdbc/Driver.java#L37-L46 抜粋

logger

これでちょっとハマった。

いざ動作確認としてみると Unable to load log4j... というエラーが出てしまった。

5.1.15 will ship with an SLF4J logger (which can then be plugged into Log4J). Unfortunately, it is not possible to ship a direct Log4J integration because the GPL is not compatible with Log4J's license. (Bug #59511, Bug #11766408)

github.com

t.co

なるほど 5.1.14以降でライセンス問題により削除されているとのこと。

削除commitは以下。

SLF4JというFacadeを使用してエラーログを出力する必要がある。

5.0系から一気にアップグレードを入れたので今回のエラーに遭遇したというわけでした。

loggerの指定をLog4JからSLF4Jへの指定するとエラーはなくなりました。

github.com