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 ...
随机推荐
- MySQL5.6启用sha256_password插件
一.背景: 使用MySQL5.6过程中,发现默认的加密插件为mysql_native_password.而sha256_password的安全程度要比mysql_native_password高,尝试 ...
- CefSharp Cookie独立 GetGlobalCookieManager
可以实现: 登陆多个京东站点,而京东各个账号互不影响. 可以完全实现Cookie独立,Cache独立. Demo用VS2017开发,C# ,NET4.5 没错,稍加改造就可以用来刷单.有Demo,有 ...
- db2数据库常见问题
db2数据库不能轻易改变表结构,不然表会进入暂挂状态,造成表被锁住. 解锁表语句:call sysproc.admin_cmd('reorg table <table name>');
- ueditorUE 去掉本地保存成功的提示框!
网上修改什么JS的太麻烦,这样比较暴力,仅供参考 这里直接修改的样式: ue.ready(function () { $(".edui-editor-mess ...
- 《Android插件化开发指南》面世
本书在京东购买地址:https://item.jd.com/31178047689.html 本书Q群:389329264 (一)这是一本什么书 如果只把本书当作纯粹介绍Android插件化技术的书籍 ...
- Go接口interface
目录 接口是什么? interface类型 空接口(interface{}) interface函数参数 interface变量存储的类型 类型断言 嵌入interface 接口是什么? Go 语言不 ...
- postgresql 删除库的时候报错database "temp_test_yang" is being accessed by other users
删除库的时候报错 ERROR: database "temp_test_yang" is being accessed by other usersDETAIL: There ar ...
- python 模拟豆瓣登录(豆瓣6.0)
最近在学习python爬虫,看到网上有很多关于模拟豆瓣登录的例子,随意找了一个试了下,发现不能运行,对比了一下代码和豆瓣网站,发现原来是豆瓣网站做了修改,增加了反爬措施. 首先看下要模拟登录的网站: ...
- 两分钟搞懂UiAutomator、UiAutomator2、Bootstrap的关系
很多同学经过一段时间的学习之后都明白了Appium的基本原理,但是越学习到后面发现出现的很多陌生名词无法弄清楚其具体作用,今天这篇文章的目的就是为了让大家来弄懂三个高频名词:UiAutomator.U ...
- 1、MySQL主从同步机制及同步中的问题处理
http://www.drupal001.com/2012/03/mysql-master-slave-troubles/ http://www.jb51.net/article/33052.htm