FAQ - Unknown system variable 'tx_isolation'

问题描述/异常栈

2023-03-02 14:42:42 CST Diagnostics: User class threw exception: java.sql.SQLException: Unknown system variable 'tx_isolation'

    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966)

    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902)

    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526)

    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673)

    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2545)

    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2503)

    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)

    at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3833)

    at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3283)

    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2297)

    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2083)

    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806)

    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)

    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

发现版本

LTS 650 update2.0

解决方案

?zeroDateTimeBehavior=CONVERT_TO_NULL&serverTimezone=Asia/Shanghai&useSSL=false

问题原因

?zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai 用户mysql8,convertToNullmysql5的写法导致使用mysql5驱动
mysql数据库的更新,在旧版本中tx_isolation是作为transaction_isolation的别名被应用的,新版本已经弃用了
旧版本也就是5.x的变量才是tx_isolation
新版本(8.x)的系统变量改成transaction_isolation

作者:林帅