create connection SQLException, url: jdbc:mysql:///xxx?....

错误代码:

ERROR 12-03 21:54:15,424 create connection SQLException, url: jdbc:mysql:///oasystem?useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true, errorCode 1193, state HY000  (DruidDataSource.java:2755) 
java.sql.SQLException: Unknown system variable 'query_cache_size'
	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3973)
	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3909)
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2527)
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2497)
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2455)
	at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1369)
	at com.mysql.jdbc.ConnectionImpl.loadServerVariables(ConnectionImpl.java:3777)
	at com.mysql.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:3240)
	at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2249)
	at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2035)
	at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:790)
	at com.mysql.jdbc.JDBC4Connection.(JDBC4Connection.java:47)
	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:425)
	at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400)
	at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1644)
	at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1710)
	at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2753)

遇到问题:在原来的项目上添加了druid的数据源,之后在运行项目过程中遇到以上问题

解决过程:

​ 1、在其它博客看到的解决方法是更改mysql-connect版本,我的驱动版本是8.0.22的,一般向下兼容,没关系

​ 2、看看数据库配置文件是否有错误

在这里插入图片描述

原来在没有添加druid的数据源之前以上数据库配置是可用的,可后面却不行了

​ 3、尝试在driver中添加’cj’,mysql驱动6版本的都需要加上’cj’(之前没有添加也可以用,奇怪!)。最终项目运行成功
在这里插入图片描述

你可能感兴趣的:(mysql,mysql)