使用mybatis连接数据库,启动服务时报错如下:
java.sql.SQLException: Unknown system variable 'tx_isolation'at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3558) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3490) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2642) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2571) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1464) ~[mysql-connector-java-5.1.10.jar:na]at com.mysql.jdbc.ConnectionImpl.getTransactionIsolation(ConnectionImpl.java:3214) ~[mysql-connector-java-5.1.10.jar:na]at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:145) ~[druid-1.0.29.jar:1.0.29]at com.alibaba.druid.pool.DruidConnectionHolder.<init>(DruidConnectionHolder.java:83) ~[druid-1.0.29.jar:1.0.29]at com.alibaba.druid.pool.DruidDataSource.put(DruidDataSource.java:1890) ~[druid-1.0.29.jar:1.0.29]at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2143) [druid-1.0.29.jar:1.0.29]
问题原因:
MySQL 服务器使用的是8.x版本,但是客户端的连接 mysql-connector-java 却是 5.1.10。
<dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.10</version>
</dependency>
解决方法:
保持版本一致,升级 mysql-connector-java版本为 8.X。
dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.20</version>
</dependency>