前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySQL 8.0版本连接报错:Could not create connection to database server.

MySQL 8.0版本连接报错:Could not create connection to database server.

作者头像
hbbliyong
发布2018-12-13 15:40:18
5.3K0
发布2018-12-13 15:40:18
举报
文章被收录于专栏:hbbliyong

 准备搭建一个Spring Boot 组合mybatis的项目,数据库采用的是MySQL 8.0.11按照以往的配置,使用插件mybatis-generator-maven-plugin生成代码时,一直报错Could not create connection to database server.如下:

[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building songci-serv 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- mybatis-generator-maven-plugin:1.3.5:generate (default-cli) @ songci-serv --- [INFO] Connecting to the Database [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.841 s [INFO] Finished at: 2018-08-22T21:32:27+08:00 [INFO] Final Memory: 13M/46M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate (default-cli) on project songci-serv: Could not create connection to database server. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException       经排查是,MySQL8.0版本需要更换驱动为“com.mysql.cj.jdbc.Driver”,之前的“com.mysql.jdbc.Driver”已经不能在MySQL 8.0版本使用了,官方文档链接:https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-api-changes.html;

描述如下:The name of the class that implements java.sql.Driver in MySQL Connector/J has changed from com.mysql.jdbc.Driver to com.mysql.cj.jdbc.Driver. The old class name has been deprecated.

另外mysql-connector-java也推荐更新到8.0的版本(https://dev.mysql.com/downloads/connector/j/)。

综上修改以下两点:

1.更新mysql-connector-java版本:

代码语言:javascript
复制
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>

2.更换驱动:

代码语言:javascript
复制
 <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1:3306/test?
useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false" userId="root" password="root"/>

配置好以上两点,运行mybatis-generator-maven-plugin,接着报错如下:

Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.5:generate (default-cli) on project songci-serv: 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. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. 报时区错误,解决方法执行命令给MySQL服务器设置时区为东八区,这个是com.mysql.cj.jdbc.Driver需要指定的:

mysql> set global time_zone='+8:00'; Query OK, 0 rows affected Navicat中命令列介面执行即可。或者在数据库连接配置中加上serverTimezone=GMT%2B8(代表东八区),如下:

代码语言:javascript
复制
connectionURL="jdbc:mysql://127.0.0.1:3306/songci?useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=GMT%2B8"
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-11-15 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档