1 | mysql版本:community-5.7.17.0 |
在连接时,需要书写的:
1 | driverClassName=com.mysql.jdbc.Driver |
上面的useUnicode=true&characterEncoding=UTF-8都是用来完成编码的设置,而useSSL=true建立SSLl连接。如果未明确设置,MySQL 5.5.45+, 5.6.26+ and 5.7.6+版本默认要求建立SSL连接。 若未设置,则会出现下列警告:
1 | WARN: Establishing SSL connection without server’s identity verification is not recommended. |
在jdbc的配置中如果myaql是6.0及以上的,会有所不同,需要按照以下设置驱动:
1 | driverClassName=com.mysql.cj.jdbc.Driver |
否则就会报错:
1 | Loading class 'com.mysql.jdbc.Driver'. This is deprecated. The new driver class is 'com.mysql.cj.jdbc.Driver'. |
同时mysql 6.0以上还需要设置时区:
1 | url=jdbc:mysql://<u>localhost</u>:3306/ssm_spring?useUnicode=true&characterEncoding=UTF-8&useSSL=true&serverTimezone=UTC |
不过值得注意的是UTC代表的是全球标准时间,我们使用的是北京时区,领先UTC八个小时。所以我们可以将时区设置为:
1 | serverTimezone=Asia/Shanghai |