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

时间:2022-09-04 18:32:40

准备搭建一个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. 解决报错&lpar;Could not create connection to database server&period;&rpar;

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

  2. jmeter连接mysql数据库报错Cannot create PoolableConnectionFactory &lpar;Could not create connection to database server&period;&rpar;

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

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

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

  4. jeecg启动报错&OpenCurlyDoubleQuote;com&period;mysql&period;jdbc&period;exceptions&period;jdbc4&period;MySQLNonTransientConnectionException&colon; Could not create connection to database server&period;”的解决办法

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

  5. pycharm2019连接mysql错误08801 ------Connection to django1&commat;localhost failed&period; &lbrack;08001&rsqb; Could not create connection to database server&period; Attempted reconnect 3 times&period; Giving up&period;

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

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

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

  7. mysql 8&period;0 java连接报错:Unknown system variable &&num;39&semi;query&lowbar;cache&lowbar;size&&num;39&semi;

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

  8. MySql 8&period;0 C&num;连接报错 MySql&period;Data&period;MySqlClient&period;MySqlException &lpar;0x80004005&rpar;&colon; Authentication to host &&num;39&semi;12&period;118&period;224&period;181&&num;39&semi; for user &&num;39&semi;root&&num;39&semi; using method &&num;39&semi;caching&lowbar;sha2&lowbar;password&&num;39&semi; failed with message&colon; Reading from t

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

  9. MYsql 8 连接报错 MySQLNonTransientConnectionException&colon; Could not create connection to database server&period;

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

随机推荐

  1. linux通过挂载系统光盘搭建本地yum仓库的方法

    1.挂载光盘 [root@localhost ~]# mount /dev/cdrom /media/cdrom/ mount: /dev/sr0 写保护,将以只读方式挂载 /media下的cdrom ...

  2. php操作mysql

  3. OS X El Capitan的 U 盘制作过程

    本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末 如果觉得本文内容过长,请前往本人 “简书”     0.在 AppStore 下载 OS X El Capitan AppStore ...

  4. android 两种定时器的实现

    在Android上常用的定时器有两种,一种是Java.util.Timer,一种就是系统的AlarmService了. 实验1:使用Java.util.Timer. 在onStart()创创建Time ...

  5. Android AIDL自动生成Java文件测试

    /******************************************************************************** * Android AIDL自动生成 ...

  6. spring初探1

    spring初探1 关于新建对象,对象依赖的三种方式比较 场景 某个交易的业务组建拆分,为原先的功能模块新写了一个业务组件 使用new. 修改上层代码的对象生成部分( 如果不是面向接口编程,简直就是灾 ...

  7. GCC 编译命令

    今天突然被同事问道一个GCC编译命令为的问题,感觉对相应内容生疏了,赶紧整理下相关内容,梳理下相关知识. GCC命令提供了非常多的命令选项,但并不是所有都要熟悉,初学时掌握几个常用的就可以了,到后面再 ...

  8. 【Ecstore2&period;0】计划任务&sol;队列&sol;导入导出 的执行问题

    [环境]CENTOS6.3 + wdcp(php5.3) [症状]可正常加入队列,但不执行队列 [原因]大部份都是用户权限造成 [原理] Ecstore2.0的导入导出.发送邮件.日常清理备份等任务操 ...

  9. Google Map Android api V2 中使用MapView遇到CameraUpdateFactory is not initialized&excl;的解决办法

    先说一下 Map V2 API Key 的问题吧: 在打包APP时需要自己生成一个XXX.keystore 用这个密室库生成的SHA1去申请的key 作为AndroidManifest.xml 中的K ...

  10. python中数字类型与处理工具

    python中的数字类型工具 python中为更高级的工作提供很多高级数字编程支持和对象,其中数字类型的完整工具包括: 1.整数与浮点型, 2.复数, 3.固定精度十进制数, 4.有理分数, 5.集合 ...