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.(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配置

如下所示

       
        
            
        



    
    
    
        
            
            
            
        
        
        
            
        
        
            
        
        
        
            
            
        
        
        
            
        
        
        
            
        
        
        

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

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

你可能感兴趣的:(idea)