[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
问题重现:
有一个表总是在写入数据的时候报2013的错误
原因分析:
官方文档,总结一下3种可能性,一般都是第一或第二种原因
首先SQLAlchemy官方对该错误的解释:
针对与数据库操作相关的错误而引发的异常,并且不一定在程序员的控制之下,例如, 发生意外断开连接,找不到数据源名称,无法处理事务,处理期间发生内存分配错误等。
此错误是DBAPI错误,源自数据库驱动程序(DBAPI),而不是SQLAlchemy本身。
OperationalError是驱动程序在被删除的数据库连接的上下文中使用的最常见(但不是唯一)错误类,或者无法连接到数据库。
原因1:备份可能达到MySQL超时限制
这里讨论的特定变量是net_read_timeout和net_write_timeout,它们分别设置为30秒和60秒。
你可以在my.cnf配置文件中根据需要设置它们来更改它们。以下是个例子。
对my.cnf进行这些更改后,必须重新启动MySQL!!!
net_read_timeout = 120
net_write_timeout = 900
更改这些设置而无需重新启动MySQL,则可以使用以下SQL语句执行此操作:
set global net_read_timeout = 120;
set global net_write_timeout = 900;
原因2:增加max_allowed_packet设置
在my.ini配置文件 mysqld 节点下添加
max_allowed_packet = 500M
配置MySQL允许的最大数据包大小,上面的500M你可以根据你的项目修改为你自己的值,只要比要导入的备份文件大就可以了。
<>原因3:可能为坏表
有时“丢失连接”错误是由损坏的表引起的。
您可以尝试设置
innodb_force_recovery = 1
重新启动mysql以查看是否有帮助。 如果是此原因,执行转储可能会修复页面缓存,你可以将其转回0或删除该配置。