mysql 8版本中引入时出现的一些异常记录
今日使用逆向工程时由于mysql版本为8版本出现了一些异常,逐一排查解决,对已出现的问题及解决方案进行记录,希望有所帮助。
如果你安装的版本为mysql的8版本则在pom.xml中将mysql的依赖版本改为如下所示。
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>
在使用驱动时,将驱动改为如下所示,由于我是在xml中使用,具体代码如下:
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/foodie-shop?&autoReconnect=TRUE&useSSL=FALSE&serverTimezone=GMT"
userId="root"
password="password">
</jdbcConnection>
问题一:
初试时由于xml里面 IDEA 将"&"符号当做了特殊字符。出现了下述异常。
Unescaped & or nonterminated character/entity reference
解决方案:
如上述代码显示将"&" 该换成"&"即可。
问题二:
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.
出现上述异常的原因是Mysql在高版本中需要指定是否需要进行SSL连接。
解决方案:
我们在URL引入时,添加useSSL=FALSE即可。
connectionURL="jdbc:mysql://localhost:3306/foodie-shop?&autoReconnect=TRUE&useSSL=TRUE&serverTimezone=GMT"
由于证书问题,上述中如果将useSSL=TRUE会产生如下的错误。
java.security.cert.CertPathValidatorException: Path does not chain with any of the trust anchors
问题三:
java.sql.SQLNonTransientConnectionException: Could not create
connection to database server. Attempted reconnect 3 times. Giving up.
出现上述问题的原因是需要在使用时,设定时区才可以正常链接。
解决方案:
在url引入时,添加serverTimezone=GMT即可解决问题。
connectionURL="jdbc:mysql://localhost:3306/foodie-shop?&autoReconnect=TRUE&useSSL=FALSE&serverTimezone=GMT"
此上所述,即完成了Mysql 8版本在逆向工程中的引入。如果仍然未能解决,请检查:
- 配置文件的url,userName,passWord是否正确。
- 检查MySQL服务是否运行。
如果仍未能解决,请下方留言。