Mysql连接错误alibaba.druid.support.logging.JakartaCommonsLoggingImpl.error create connection SQLExceptio

具体报错如下:

18-Jun-2020 10:01:10.426 严重 [Druid-ConnectionPool-Create-1158666489] com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl.error create connection SQLException, url: jdbc:mysql://localhost:3306/facemask?serverTimezone=UTC&                   useUnicode=true&characterEncoding=UTF-8&useSSL=false, errorCode 1193, state HY000
 java.sql.SQLException: Unknown system variable 'query_cache_size'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2505)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1370)
	at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3862)
	at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3290)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2299)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085)
	at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795)
	at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:327)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1643)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1709)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2715)

这个问题困扰了我两天,最后才发现是Mysql驱动配置的问题。
不同版本的Mysql配置不一样。

Mysql5.0版本的对应配置:
driverClassName属性对应的值为com.mysql.jdbc.Driver

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url"
                  value="jdbc:mysql://localhost:3306/facemask?serverTimezone=UTC&
                  useUnicode=true&characterEncoding=UTF-8&useSSL=false"/>
        <property name="username" value="****"/>
        <property name="password" value="****"/>
    </bean>

Mysql8.0+版本的对应配置:
driverClassName属性对应的值为com.mysql.cj.jdbc.Driver

<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
        <property name="url"
                  value="jdbc:mysql://localhost:3306/facemask?serverTimezone=UTC&
                  useUnicode=true&characterEncoding=UTF-8&useSSL=false"/>
        <property name="username" value="****"/>
        <property name="password" value="****"/>
    </bean>

你可能感兴趣的:(mysql,jdbc,数据库)