MySQL8的jdbc配置错误问题(MySQL8数据库变动)

2019-04-09  本文已影响0人  单名一个冲

小编在一次使用mybatis-generator生成映射时,由于从mysql5切换到了mysql8.0,报了如下错误:

[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.demo:mybatis-generator >---------------------
[INFO] Building mybatis-generator 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- mybatis-generator-maven-plugin:1.3.7:generate (default-cli) @ mybatis-generator ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.497 s
[INFO] Finished at: 2019-04-09T21:47:48+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project mybatis-generator: 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

错误分析:

1. 修改后的maven引入mysql连接包的版本:

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.7</version>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.15</version>
        </dependency>
    </dependencies>
    <!-- <configuration>
        配置文件的路径
        <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
        <overwrite>true</overwrite>
    </configuration> -->
</plugin>

2. MySQL8.0+的数据库连接驱动从com.mysql.jdbc.Driver更换到了com.mysql.cj.jdbc.Driver

3. MySQL8.0+的数据库连接需要指定serverTimezone=UTC;
如果直接在jdbc连接URL中添加serverTimezone=UTC会报错误
,如下:

[ERROR] XML Parser Error on line 27: 对实体 "serverTimezone" 的引用必须以 ';' 分隔符结尾。

只需要修改为"&amp;serverTimezone=UTC"即可,如下例子:**

<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
    connectionURL="jdbc:mysql://127.0.0.1:3306/springdata?characterEncoding=utf-8&amp;serverTimezone=UTC"
    userId="root" password="password">
</jdbcConnection>
上一篇下一篇

猜你喜欢

热点阅读