golang mysql 的 packet sequence error 这个错
在公司用golang 写了个插入外链数据的服务,这服务是2016年写的,大概作用就是,python 爬取的数据,要同步到 wordpress中,golang就负责,将数据整理,图片下载弄到 wordpress中,当然也不止这些服务,本来这个服务之前运行的好好的,可是最近又上了新的数据采集道后,这个服务就显得不稳定了,后台日志,经常报
packet sequence error
这个错,纠缠了很久,一直找不到原因,在github上面发现原来作者也有这个坑 https://github.com/ziutek/mymysql/issues/105
其实,这个错,报的就是一个多协程(线程)的问题,其实说来也怪,我们最近有几个项目都用golang写的就从来没有报过这个错,为啥这个就报这个错,反复的review 代码
var db *mysql.DB //定义了全局的db func init() {
db, _ = MysqlConn.Get().(*mysql.DB) //封装的线程池里拿
}
目前就感觉这个是有点毛病,好好看了下golang 的init函数
1.初始化不能采用初始化表达式初始化的变量。
2.程序运行前的注册。
3.实现sync.Once功能。
4.其他
肯定这个初始化的时候不能写到 init中,于是换了个写法
func GetDB() *mysql.DB {
return MysqlConn.Get().(*mysql.DB)
}
直接通过调用GetDB()获取数据的链接,然后再操作,观查了一下午,暂时没有报这个错
golang mysql 的 packet sequence error 这个错的更多相关文章
- 连接 MySQL 报错:Lost connection to MySQL server at 'reading authorization packet', system error: 34
报错信息: Lost connection to MySQL server at 解决方案: use mysql; ; flush privileges; 参考: https://blog.csdn. ...
- 使用cmd命令登录mysql数据库时报2013-Lost connection to MYSQL server at 'waiting for initial communication packet',system error:0
[错误内容]:SQL Error (2013): Lost connection to MySQL server at 'waiting for initial communication packe ...
- MySQL远程连接丢失问题解决方法Lost connection to MySQL server at ‘reading initial communication packet’, system error: 0
最近远程连接mysql总是提示 Lost connection 很明显这是连接初始化阶段就丢失了连接的错误 其实问题很简单,都是MySQL的配置文件默认没有为远程连接配置好,只需要更改下MySQL的配 ...
- 虚拟机中MySQL连接问题:Lost connection to MySQL server at 'reading initial communication packet, system error: 0 以及 host is not allowed to connect mysql
环境:在VirtualBox中安装了Ubuntu虚拟机,网络使用了NAT模式,开启了端口转发. 局域网内其他计算机访问虚拟机中的MySQL Server出现两个问题: Lost connection ...
- ERROR 2013 (HY000): Lost connection to MySQL server at 'waiting for initial communication packet', system error: 2
ERROR (HY000): Lost connection to MySQL server at 'waiting for initial communication packet', system ...
- Lost connection to MySQL server at ‘reading initial communication packet', system error: 0 mysql远程连接问题
在用Navicat for MySQL远程连接mysql的时候,出现了 Lost connection to MySQL server at ‘reading initial communicatio ...
- mysql远程连接问题 Lost connection to MySQL server at ‘reading initial communication packet', system error: 0
在用Navicat for MySQL远程连接mysql的时候,出现了 Lost connection to MySQL server at ‘reading initial communicatio ...
- ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0
最近遇到一个MySQL连接的问题,远程连接MySQL时遇到"ERROR 2013 (HY000): Lost connection to MySQL server at 'reading a ...
- 在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as c rashed and should be repaired when using LOCK TABLES
在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as cra ...
随机推荐
- python之动态参数 *args,**kwargs和命名空间
一.函数的动态参数 *args,**kwargs, 形参的顺序1.你的函数,为了拓展,对于传入的实参数量应该是不固定,所以就需要用到万能参数,动态参数,*args, **kwargs 1,*args ...
- AssetBundle打包
为热更新打基础(xlua\tolua) 素材.源码链接:http://www.sikiedu.com/course/74/task/1812/show 一.AssetBundle的定义和作用 1,As ...
- ORACLE表数据误删除的恢复方法(提交事务也可以)
ORACLE表数据误删除的恢复方法(提交事务也可以) 缓存加时间戳 开启行移动功能:ALTER TABLE tablename ENABLE row movement 把表还原到指定时间点:flash ...
- Eclipse maven hadoop -- java.io.IOException: No FileSystem for scheme: hdfs
2019-01-10 概述 今天在Windows系统下新安装了Eclipse和maven的环境,想利用Maven构建一个Hadoop程序的,结果却发现程序运行时一直报 “No FileSystem f ...
- photoshop编辑pdf文件
对于PDF文件透明背景的问题 PDF文件背景是透明的,如何使其变成白色 怎样通过photoshop打开多页PDF,编辑后仍保存为多页 注意shift全选,"页面选项"处的'裁剪到' ...
- mysql数据去重并排序使用distinct 和 order by 的问题
比如直接使用: SELECT distinct mobileFROM table_aWHERE code = 123ORDER BY a_ime desc 在本地mysql数据库没有错,在线上的数据库 ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- [Ynoi2018]五彩斑斓的世界
题目描述 二阶堂真红给了你一个长为n的序列a,有m次操作 1.把区间[l,r]中大于x的数减去x 2.查询区间[l,r]中x的出现次数 题解 做YNOI真**爽... 我们发现这道题的操作非常诡异,把 ...
- MySQL安装-windows安装
windows下安装MySQL 在windows下面安装MySQL 本文以5.7.17为示例 MySQL下载 官网:https://dev.mysql.com/downloads/mysql/ 本次安 ...
- saltstack主机管理项目:动态调用插件解析-模块解析(五)
一.动态调用插件解析 1.目录结构 1.base_module代码解析: def syntax_parser(self,section_name,mod_name,mod_data): print(& ...