mysql 错误解决

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介: mysql 错误解决

1.错误提示

使用mybatis代码生成工具时,提示时区乱码错误,如下所示

C:\springinit\demo\src\main\java>java -jar mybatis-generator-core-1.3.7.jar -configfile generatorConfig.xml -over
write
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. Th
e driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
java.sql.SQLException: The server time zone value '???ú±ê×??±??' is unrecognized or represents more than one t
ime 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.
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
        at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
        at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)
        at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)
        at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
        at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
        at org.mybatis.generator.internal.JDBCConnectionFactory.getConnection(JDBCConnectionFactory.java:84)
        at org.mybatis.generator.config.Context.getConnection(Context.java:542)
        at org.mybatis.generator.config.Context.introspectTables(Context.java:446)
        at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:257)
        at org.mybatis.generator.api.MyBatisGenerator.generate(MyBatisGenerator.java:189)
        at org.mybatis.generator.api.ShellRunner.main(ShellRunner.java:117)
Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '???ú±ê×??±
??' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (v
ia the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time z
one support.
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
        at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
        at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)
        at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2234)
        at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2258)
        at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)
        at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)
        at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)
        ... 9 more


2.解决办法


配置jdbcConnection,添加servertimezone配置


如下所示

<!--数据库链接URL,用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost/mdblog" userId="root" password="root" >
            <property name="serverTimezone" value="UTC"/>
        </jdbcConnection>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <!-- 数据库驱动-->
    <classPathEntry  location="mysql-connector-java-8.0.13.jar"/>
    <context id="DB2Tables"  targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据库链接URL,用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost/mdblog" userId="root" password="root" >
            <property name="serverTimezone" value="UTC"/>
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 生成模型的包名和位置-->
        <javaModelGenerator targetPackage="cn.goingtodo.domain" targetProject=".">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- 生成映射文件的包名和位置-->
        <sqlMapGenerator targetPackage="cn.goingtodo.mapping" targetProject=".">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="cn.goingtodo.IDao" targetProject=".">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
        <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
    </context>
</generatorConfiguration>


3.效果


C:\springinit\demo\src\main\java>java -jar mybatis-generator-core-1.3.7.jar -configfile generatorConfig.xml -overwrite
Table Configuration user matched more than one table (mdblog..user,mysql..user)
Cannot obtain primary key information from the database, generated objects may be incomplete
Cannot obtain primary key information from the database, generated objects may be incomplete
Existing file C:\springinit\demo\src\main\java\.\cn\goingtodo\domain\User.java was overwritten
Existing file C:\springinit\demo\src\main\java\.\cn\goingtodo\IDao\UserMapper.java was overwritten
MyBatis Generator finished successfully, there were warnings.


切记数据库配置表user要指明,数据库名.表明, test.user, mdblog.user是不一样的,不然会混淆。


4.再来一遍


C:\springinit\demo\src\main\java>java -jar mybatis-generator-core-1.3.7.jar -configfile generatorConfig.xml -overwrite
Table Configuration mdblog.user matched more than one table (mdblog..user,mysql..user)
Cannot obtain primary key information from the database, generated objects may be incomplete
Cannot obtain primary key information from the database, generated objects may be incomplete
Existing file C:\springinit\demo\src\main\java\.\cn\goingtodo\domain\User.java was overwritten
Existing file C:\springinit\demo\src\main\java\.\cn\goingtodo\IDao\UserMapper.java was overwritten
Existing file C:\springinit\demo\src\main\java\.\cn\goingtodo\domain\User.java was overwritten
Existing file C:\springinit\demo\src\main\java\.\cn\goingtodo\domain\UserWithBLOBs.java was overwritten
Existing file C:\springinit\demo\src\main\java\.\cn\goingtodo\IDao\UserMapper.java was overwritten
MyBatis Generator finished successfully, there were warnings.


5.附录


mysql-connector-java-8.0.13.jar
mybatis-generator-core-1.3.7.jar

自动生成不易啊,摸索了一下。。。。。。


相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
关系型数据库 MySQL 网络安全
MySql出现#1036 – Table ‘ ‘ is read only 错误解决方法
MySql出现#1036 – Table ‘ ‘ is read only 错误解决方法
612 0
|
关系型数据库 MySQL 数据安全/隐私保护
【错误解决】本地计算机上的mysql服务启动停止后,某些服务在未由其他服务或程序使用时将自动停止
转载请注明出处:http://blog.csdn.net/qq_26525215 本文源自【大学之旅_谙忆的博客】 在启动mysql服务时出现该错误: 本地计算机上的mysql服务启动停止后,某些服务在未由其他服务或程序使用时将自动停止。
3888 0
|
关系型数据库 MySQL 数据库
【错误解决】MySQL出现Can&#39;t connect to MySQL server on &#39;localhost&#39; (10060)错误
转载请注明出处:http://blog.csdn.net/qq_26525215 本文源自【大学之旅_谙忆的博客】 今天连接数据库遇到一个问题, 错误提示: Can’t connect to MySQL server on ‘localhost’ (10060) 开始弄了很久,没弄好。
1391 0