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

相关推荐
StarRocks_labs44 分钟前
StarRocks Community Monthly Newsletter (Jun)
数据库·starrocks·数据湖·物化视图·存算分离
光电的一只菜鸡2 小时前
ubuntu之坑(十五)——设备树
linux·数据库·ubuntu
ob熔天使——武2 小时前
MySQL
数据库·mysql
小光学长3 小时前
基于vue框架的防疫物资仓库管理系统09y38(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库
野生技术架构师6 小时前
MySQL数据实时同步到Elasticsearch的高效解决方案
数据库·mysql·elasticsearch
白仑色7 小时前
Oracle 高可用性与安全性
数据库·oracle·数据安全·goldengate·高可用架构
紫无之紫7 小时前
SQL性能调优经验总结
数据库·sql·性能调优
CZZDg8 小时前
Redis Sentinel哨兵集群
java·网络·数据库
__风__8 小时前
PostgreSQL ExecInitIndexScan 函数解析
数据库·postgresql
小云数据库服务专线8 小时前
GaussDB in的用法
数据库·sql·gaussdb