[Go] 解决packets.go:36: read tcp 127.0.0.1:51139->127.0.0.1:3306: wsarecv: An established connection was aborted by the software in your host ma chine.
2023-02-18 15:36:29 时间
这是因为数据库的超时时间比较短,连接被mysql服务关闭了
程序还在使用旧连接查询数据库
比如gorm
我们程序里设置下时间旧可以了,时间比超时时间短一些
DB.DB().SetConnMaxLifetime(59 * time.Second)
DB, err = gorm.Open("mysql", dsn) if err != nil { log.Println(err) panic("数据库连接失败!") return err } DB.SingularTable(true) DB.LogMode(true) DB.DB().SetMaxIdleConns(10) DB.DB().SetMaxOpenConns(100) DB.DB().SetConnMaxLifetime(59 * time.Second)
相关文章
- MongoDB(4)- MongoDB与Python的交互
- MongoDB(3)- 数据的导入导出
- MongoDB(2)- MongoDB的基本操作
- MongoDB(1)- MongoDB数据库介绍与安装
- Linux(六):系统运维常用命令
- Linux(五):Linux的文档编辑器Vi
- Linux(四):Linux的打包和压缩详解
- Linux(三):Linux的目录及相关作用
- Linux(二):Linux的灵魂
- Linux(一):Linux操作系统
- Linux环境下安装配置Mysql
- (一)Git——安装与初始化
- (二)Git——基本操作
- (三)Git——分支
- (四)Git——团队协作
- Git——从入门到入云
- Linux嵌入式开发——shell命令
- Linux环境下接口调试利器:cURL
- 基于Linux系统的本地Yum源搭建与配置(ISO方式、RPM方式)
- 【Golang】反射的三大laws