Mysql8连接信息变动
程序员文章站
2022-05-30 13:22:02
...
昨天公司DBA把测试库的MySQL从5.7升到了8.1,然后今天一上午项目都启动不了,要修改的地方不多,但是涉及的影响很大,一直到下午才搞定。在此记录下。
首先贴出来正确的连接信息:
jdbc:mysql://localhost:3306/db?useSSL=false&serverTimezone=UTC
MySQL的JDBC驱动使用了新的包名,所以我们需要将driver的值改为com.mysql.cj.jdbc.Driver
新版本的MySQL要求是否进行ssl连接,所以我们需要设置useSSL=false或者useSSL=true
url中如果driver没有添加cj,则会在连接的时候出现以下错误提示:
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.
url中如果没有设置useSSL=false,则会在连接的时候出现以下错误提示:
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 <br>SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate<br> 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<br> verification.
url中如果没有设置serverTimezone=UTC,则会在连接的时候出现以下错误提示:
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.
上一篇: jdbc通过JNDI获取tomcat6连接池的连接
下一篇: pssh使用