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

相关推荐
我爱娃哈哈2 分钟前
告别Redis瓶颈:Caffeine本地缓存优化实战指南
数据库·redis·缓存
虾说羊4 分钟前
transferManager为什么在工作中禁止使用 (怎么进行优化 怎么避免多线程的堵塞)
java·服务器·数据库
机灵猫7 分钟前
Redis 内部机制:持久化、内存淘汰与延迟优化
数据库·redis·缓存
小成很成11 分钟前
sql 开发基础版(命令)
数据库·mysql
ClouGence12 分钟前
打通复杂医疗数据链路:某头部医疗服务商的数据底座落地经验分享
数据库·经验分享·数据分析
我在北国不背锅15 分钟前
Milvus向量数据库索引说明
数据库·milvus
9稳15 分钟前
基于PLC的液体自动混合加热控制系统设计
开发语言·网络·数据库·labview·plc
TG:@yunlaoda360 云老大21 分钟前
华为云国际站代理商Image主要有什么作用呢?
数据库·游戏·华为云
SadSunset29 分钟前
(35)使用Spring的AOP
java·数据库·spring
star-keke1 小时前
Python pip安装依赖redis被自动降级的问题
数据库·redis·pip