360SDN.COM

首页/MySQL/列表

Mysql版本的相关问题:com.mysql.cj.jdbc.Driver和com.mysql.jdbc.Driver本的相关问题

来源:  2018-09-14 16:22:27    评论:0点击:

   来源:  https://blog.csdn.net/LJX_ahut/article/details/80928132

1. 在使用mysql时控制台日志报错如下:

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. 

查阅资料之后发现是由于版本的问题,mysql5用的驱动url是com.mysql.jdbc.Driver,mysql6以后用的是com.mysql.cj.jdbc.Driver。版本不匹配便会报驱动类已过时的错误。

?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false

 

2. JDBC连接Mysql6 com.mysql.cj.jdbc.Driver, 需要指定时区serverTimezone,否则会报如下错误,   

 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: 
Cannot create PoolableConnectionFactory (The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.)WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
 

3.还有一个警告:

WARN: Establishing SSL connection without server’s identity verification is not recommended. 
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection 
must be established by default if explicit option isn’t set. 
For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. 
You need either to explicitly disable SSL by setting useSSL=false, 
or set useSSL=true and provide truststore for server certificate verification.

不推荐不使用服务器身份验证来建立SSL连接。 
如果未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求建立SSL连接。 
为了符合当前不使用SSL连接的应用程序,verifyServerCertificate属性设置为’false’。 
如果你不需要使用SSL连接,你需要通过设置useSSL=false来显式禁用SSL连接。 
如果你需要用SSL连接,就要为服务器证书验证提供信任库,并设置useSSL=true

SSL – Secure Sockets Layer(安全套接层)

所以,使用mysql6的连接字符串建议使用如下:

jdbc.url=jdbc:mysql://localhost:3306/your_database?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
 

网上有大神给出了一个更为详细的连接字符串,建议参考


mysql.url=jdbc:mysql://127.0.0.1:3306/dbname?serverTimezone=UTC&useUnicode=true&characterEncoding=utf8&characterSetResults=utf8&useSSL=false&verifyServerCertificate=false&autoReconnct=true&autoReconnectForPools=true&allowMultiQueries=true 
ps:以上配置的写法是写在单独的配置文件properties中,使用xml文件配置的写法略有不同,需要将每一个配置用分号; 隔开,需要注意的是分号;在xml中需要转义,例如

properties文件中配置写法

dbc.url=jdbc:mysql://localhost:3306/your_database?characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false

xml文件中的配置写法

<property name="url" value="jdbc:mysql://localhost/lujx?serverTimezone=UTC&amp;useSSL=false" />

为您推荐

友情链接 |九搜汽车网 |手机ok生活信息网|ok生活信息网|ok微生活
 Powered by www.360SDN.COM   京ICP备11022651号-4 © 2012-2016 版权