MySQL 8.0版本连接报错:Could not create connection to database server.
准备搭建一个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&characterEncoding=utf-8&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&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8"
MySQL 8.0版本连接报错:Could not create connection to database server.的更多相关文章
- 解决报错(Could not create connection to database server.)
org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory 尝试多种方法后发现是由于mysq ...
- jmeter连接mysql数据库报错Cannot create PoolableConnectionFactory (Could not create connection to database server.)
今天在学习jmeter的jdbc取样器,发现在配置完JDBC Connection Configuration和JDBC Request后,点击运行.在查看结果树中显示响应数据: Cannot cre ...
- 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 ...
- jeecg启动报错“com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.”的解决办法
在运行"maven build"-->"tomcat:run"之后,报如下错误: com.mysql.jdbc.exceptions.jdbc4.MySQ ...
- 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 ...
- [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. 点击这里 ...
- 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. ...
- 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
- MYsql 8 连接报错 MySQLNonTransientConnectionException: Could not create connection to database server.
本地安装mysql 是8 项目中数据驱动 也要求是 8 <dependency> <groupId>mysql</groupId> <artifactId&g ...
随机推荐
- 航班座位_hihocoder
题目2 : 航班座位 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi在给一个家庭旅游团订某次航班的机票.该航班的飞机一共有N排座位,每排座位有10个座位,从左到右 ...
- Js 运行机制和Event Loop
一.为什么JavaScript是单线程? JavaScript语言的一大特点就是单线程,也就是说,同一个时间只能做一件事.那么,为什么JavaScript不能有多个线程呢?这样能提高效率啊. Java ...
- jQuery倒计时组件(jquery.downCount.js)
//html <span class="days">00</span> <span class="hours">00< ...
- Meltdown Attack
1. 引言 2018年1月3日,Google Project Zero(GPZ)团队安全研究员Jann Horn在其团队博客中爆出CPU芯片的两组漏洞,分别是Meltdown与Spectre. Mel ...
- mysql根据查询结果批量更新多条数据(插入或更新)
mysql根据查询结果批量更新多条数据(插入或更新) 1.1 前言 mysql根据查询结果执行批量更新或插入时经常会遇到1093的错误问题.基本上批量插入或新增都会涉及到子查询,mysql是建议不要对 ...
- 初学Socket通信
1.Socket:Socket就是套接字.客户端与服务器之间通信用的.Socket接口是TCP/IP网络的API. 2.SYN是TCP/IP建立连接时使用的握手信号.在客户端和服务器之间建立正常的TC ...
- 基于 TensorFlow 在手机端实现文档检测
作者:冯牮 前言 本文不是神经网络或机器学习的入门教学,而是通过一个真实的产品案例,展示了在手机客户端上运行一个神经网络的关键技术点 在卷积神经网络适用的领域里,已经出现了一些很经典的图像分类网络,比 ...
- java并发面试
1.在java中守护线程和本地线程区别? java中的线程分为两种:守护线程(Daemon)和用户线程(User). 任何线程都可以设置为守护线程和用户线程,通过方法Thread.setDaemon( ...
- 使用Nginx做图片服务器时候,配置之后图片访问一直是 404问题解决
我的错误配置是: 服务器文件根地址: 想通过浏览器输入这个地址访问到图片: 但是会发现文件找不到会一直404,原因是根路径配置错误,来看下root路径原理: root 配置的意思是,会在root配置的 ...
- [Swift]LeetCode119. 杨辉三角 II | Pascal's Triangle II
Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle. Note t ...