[INFO] --- mybatis-generator-maven-plugin:1.3.7:generate (default-cli) @ myproject ---
[INFO] Connecting to the Database
Wed Jun 08 17:28:08 CST 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.571 s
[INFO] Finished at: 2022-06-08T17:28:08+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.mybatis.generator:mybatis-generator-maven-plugin:1.3.7:generate (default-cli) on project myproject: Communications link failure
[ERROR]
[ERROR] The last packet successfully received from the server was 536 milliseconds ago. The last packet sent successfully to the server was 518 milliseconds ago.
[ERROR] -> [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
<classPathEntry
location="/Users/${user.name}/.m2/repository/mysql/mysql-connector-java/5.1.47/mysql-connector-java-5.1.47.jar"/>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://myhost:3306/mydb?useUnicode=true"
userId="myname" password="mypwd"/>
mvn mybatis-generator:generate -Dmybatis.generator.configurationFile=src/test/resources/generatorConfig.xml -Dmybatis.generator.overwrite=true
网络问题那么久排查网络咯,检查网络与端口是否互通,可以使用telnet命令检查,如果没有报错则说明host与端口服务都是正常的
telnet host port
host/port/账号/密码检查,可以本地mysql尝试连接,根据响应提示检查是否权限问题?账号密码错误问题
mysql -hmyhost -umyuser -pmypwd -Pmyport
查看服务器版本:5.7x
show global variables like 'version';
查看驱动版本:配置中有指定=mysql-connector-java-5.1.47
网络/账号/版本均正常,但依然报错网络问题,查询资料结论为版本问题,当版本8.x客户端连接版本5.x的服务端会有此类问题,检查发现本地mysql客户端版本确实是8.x,同样说明mybatis生成器连接服务端是基于本地客户端完成的
其实错误日志中的warn已经给出了提示,连接url增加useSSL=false即可,或者提供ssl证书
jdbc:mysql://myhost:3306/mydb?useUnicode=true&useSSL=false