MySQL8.0.37使用过程中返回的两个错误(Error Code: 3780和Communications link failure)

文章目录

  • 小结
  • 问题及解决
    • [Error Code: 3780. Referencing column 'xxx' and referenced column 'xxx' in foreign key constraint 'zzz' are incompatible](#Error Code: 3780. Referencing column 'xxx' and referenced column 'xxx' in foreign key constraint 'zzz' are incompatible)
    • [com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure](#com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure)
  • 参考

小结

最近在使用MySQL8.0.37过程中返回的两个错误(Error Code: 3780和Communications link failure),进行了解决。

问题及解决

Error Code: 3780. Referencing column 'xxx' and referenced column 'xxx' in foreign key constraint 'zzz' are incompatible

出更 这个问题的原因是因为数据表的COLLATE属性不匹配,对数据表的创建进行以下修改:

sql 复制代码
/* Create Tables */

CREATE TABLE `XXX_LIST`
(
	`XXXID` VARCHAR(20) NOT NULL,
	`CONFIGURATIONID` INT NOT NULL,
	CONSTRAINT `PK_XXX_LIST_CONFIGURATION` PRIMARY KEY (`XXXID` ASC)
) 
;

修改COLLATE属性一致,问题解决。

sql 复制代码
/* Create Tables */

CREATE TABLE `XXX_LIST`
(
	`XXXID` VARCHAR(20) NOT NULL,
	`CONFIGURATIONID` INT NOT NULL,
	CONSTRAINT `PK_XXX_LIST_CONFIGURATION` PRIMARY KEY (`XXXID` ASC)
) ENGINE=InnoDB 
    DEFAULT CHARSET=latin1 
    COLLATE latin1_swedish_ci;
;

具体报错如下:

java 复制代码
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
	at com.mysql.cj.jdbc.exceptions.SQLError.createCommunicationsException(SQLError.java:174) ~[mysql-connector-j-8.3.0.jar:8.3.0]
	at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:64) ~[mysql-connector-j-8.3.0.jar:8.3.0]
	at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:815) ~[mysql-connector-j-8.3.0.jar:8.3.0]
	at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:438) ~[mysql-connector-j-8.3.0.jar:8.3.0]
	at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:241) ~[mysql-connector-j-8.3.0.jar:8.3.0]
	at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:189) ~[mysql-connector-j-8.3.0.jar:8.3.0]
    。。。。。。 省略   。。。。。。
Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

进行各种检查,发现数据库连接有问题,进行相应的重置,问题解决。

参考

stackoverflow: Error when foreign referencing in mySQL (Error 3780)
stackoverflow: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure Spring boot

相关推荐
Little-Hu36 分钟前
QML TextEdit组件
java·服务器·数据库
保持学习ing2 小时前
day1--项目搭建and内容管理模块
java·数据库·后端·docker·虚拟机
宇钶宇夕3 小时前
EPLAN 电气制图:建立自己的部件库,添加部件-加SQL Server安装教程(三)上
运维·服务器·数据库·程序人生·自动化
爱可生开源社区4 小时前
SQLShift 重磅更新:支持 SQL Server 存储过程转换至 GaussDB!
数据库
贾修行4 小时前
SQL Server 空间函数从入门到精通:原理、实战与多数据库性能对比
数据库·sqlserver
傲祥Ax4 小时前
Redis总结
数据库·redis·redis重点总结
一屉大大大花卷5 小时前
初识Neo4j之入门介绍(一)
数据库·neo4j
周胡杰5 小时前
鸿蒙arkts使用关系型数据库,使用DB Browser for SQLite连接和查看数据库数据?使用TaskPool进行频繁数据库操作
前端·数据库·华为·harmonyos·鸿蒙·鸿蒙系统
wkj0016 小时前
navicate如何设置数据库引擎
数据库·mysql
赵渝强老师6 小时前
【赵渝强老师】Oracle RMAN的目录数据库
数据库·oracle