1.问题

初始化数据库错误,init datasource error, url: jdbc:mysql://localhost:3306/book

Untitled

2.原因

本地下载安装的MySQL服务是8.0的,但是数据库驱动使用了5.X版本的

3.解决办法

(1)将数据库驱动更新为符合数据库版本的

MySQL :: Begin Your Download

再次启动,出现如下错误:

Untitled

Loading class com.mysql.jdbc.Driver'. This is deprecated. The new driver class iscom.mysql.cj.jdbc.Driver’. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Sun Oct 31 17:28:28 CST 2021 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.

提到了driver类的错误和默认使用SSL连接所导致的错误

(2)解决driver错误,更新driver类

com.mysql.jdbc.Driver更新为com.mysql.cj.jdbc.Driver

(3)更改连接URL,设置useSSL=false

再次执行出现如下错误:

Untitled

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.

服务器时区值错误,所以要配置规范服务器时区值:

(4)更改连接URL,增加服务器时区值配置

url=jdbc:mysql://localhost:3306/book?useSSL=false&serverTimezone=GMT%2B8

GMT%2B8表示时区东八区

再次执行,连接成功

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐