MySQL8.0连接中的几个问题

问题汇总

JDBC 驱动最新版问题

报错原因

  • 使用了MySQL的最新版 JDBC 连接驱动

报错提示

1
java.sql.SQLException: 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.

解决方案

1
jdbcUrl=jdbc:mysql://localhost:3306/person

后面加上:

1
jdbcUrl=jdbc:mysql://localhost:3306/person?serverTimezone=UTC

但如果你的 jdbcUrl 类似下面:

1
jdbcUrl=jdbc:mysql://localhost:3306/person?serverTimezone=UTC&characterEncoding=utf-8

就是有多个params的时候需要以&分开,但 &要改为 & 如下:

1
jdbcUrl=jdbc:mysql://localhost:3306/spring?serverTimezone=UTC&ampcharacterEncoding=utf-8

注意

  • 在使用配置文件或c3p0-xml配置的情况下 多个params间以 & 分割
  • 在 JDBCUtils 老版方法中 多个params中用 &amp 分割