准备搭建一个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版本:

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>

2.更换驱动:

 <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(代表东八区),如下:

connectionURL="jdbc:mysql://127.0.0.1:3306/songci?useUnicode=true&amp;characterEncoding=utf8&amp;useSSL=false&amp;serverTimezone=GMT%2B8"

MySQL 8.0版本连接报错:Could not create connection to database server.的更多相关文章

  1. 解决报错(Could not create connection to database server.)

    org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory 尝试多种方法后发现是由于mysq ...

  2. jmeter连接mysql数据库报错Cannot create PoolableConnectionFactory (Could not create connection to database server.)

    今天在学习jmeter的jdbc取样器,发现在配置完JDBC Connection Configuration和JDBC Request后,点击运行.在查看结果树中显示响应数据: Cannot cre ...

  3. java项目连接jdbc报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server

    java项目连接jdbc报错:com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not creat ...

  4. jeecg启动报错“com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.”的解决办法

    在运行"maven build"-->"tomcat:run"之后,报如下错误: com.mysql.jdbc.exceptions.jdbc4.MySQ ...

  5. pycharm2019连接mysql错误08801 ------Connection to django1@localhost failed. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up.

    Error:Connection to django1@localhost failed. [08001] Could not create connection to database server ...

  6. [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up IDEA2019的database插件无法链接mysql的解决办法(08001错误)

    [08001] Could not create connection to database server. Attempted reconnect 3 times. Giving up. 点击这里 ...

  7. mysql 8.0 java连接报错:Unknown system variable 'query_cache_size'

    java连接mysql 8.0.11报错 java.sql.SQLException: Unknown system variable 'query_cache_size' at com.mysql. ...

  8. MySql 8.0 C#连接报错 MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to host '12.118.224.181' for user 'root' using method 'caching_sha2_password' failed with message: Reading from t

    解决方法 在连接字符串后面加上   SslMode=None 

  9. MYsql 8 连接报错 MySQLNonTransientConnectionException: Could not create connection to database server.

    本地安装mysql 是8 项目中数据驱动 也要求是 8 <dependency> <groupId>mysql</groupId> <artifactId&g ...

随机推荐

  1. vue 源码学习二 实例初始化和挂载过程

    vue 入口 从vue的构建过程可以知道,web环境下,入口文件在 src/platforms/web/entry-runtime-with-compiler.js(以Runtime + Compil ...

  2. 常见的UI框架

    移动端框架 1.Admui 管理系统快速开发框架--http://docs.admui.com/ 为什么选择Admui?代码开源--开放所有源码,不存在任何加密混淆代码,安全全程可控,开箱即用--包含 ...

  3. Servlet 自定义标签

    自定义标签 1)用户定义的一种jsp标记,当一个含有自定义标签的jsp页面被jsp引擎编译成servlet时,tag标签被转化成了对一个称为 标签处理类 的对象的操作.于是,当jsp页面被jsp引擎转 ...

  4. framework7 入门(基础布局)

    个人认为framework7是个很好的移动端框架,自带路由.下拉刷新.无限加载.时间线.各种dialog.环形图等,基本能满足大部分app的需求,可以和vue,webpack 等各种搭配. 这里讲一下 ...

  5. jenkins自动化工具使用教程

    自动化构建.测试.部署.代码检测越来越重要.主要有一下几点原因 1.  企业做大,项目变多,多端支持(web,h5,小程序等) 2.  微服务提倡高内聚低耦合,项目因拆分变多 3.  DevOps自动 ...

  6. JavaSSM框架面试

    一.Spring面试题 1.Spring 在ssm中起什么作用? Spring:轻量级框架 作用:Bean工厂,用来管理Bean的生命周期和框架集成. 两大核心: 1.IOC/DI(控制反转/依赖注入 ...

  7. WinRAR存在严重的安全漏洞影响5亿用户

    WinRAR可能是目前全球用户最多的解压缩软件,近日安全团队发现并公布了WinRAR中存在长达19年的严重安全漏洞,这意味着有可能超过5亿用户面临安全风险. 该漏洞存在于所有WinRAR版本中包含的U ...

  8. [Swift]LeetCode403. 青蛙过河 | Frog Jump

    A frog is crossing a river. The river is divided into x units and at each unit there may or may not ...

  9. zuul网关入门(一、网关具有的功能)

    1. zuul网关入门(一.网关具有的功能) 1.1. 基本场景 1.1.1. API网关的由来 1.1.2. API网关基本功能 1.2. 高级应用 1.2.1. 亮点 可动态发布的过滤器机制 1. ...

  10. 1.Django安装与运行

    Django基本配置 Python的WEB框架有Django.Tornado.Flask 等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定.模板引擎.缓存.Se ...