错误提示:
InterfaceError: Can't connect to MySQL server on '127.0.0.1:3306' (10055 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。)
尝试的解决方法:
1.可能是并发连接过多(有可能都是time-wait),因此可以这样来处理下:
减小Windows中 TcpTimedWaitDelay时间可解决此类问题,默认情况下为240(未设置的情况下也是这个数值)。此项设置需要到注册表如下位置进行设置:[HKEY_LOCAL_MACHINE] [SYSTEM] [CurrentControlSet] [Services] [Tcpip] [Parameters] [TcpTimedWaitDelay]如果注册表中没有TcpTimedWaitDelay这个项目,请增加这个项目,并设置为双字节(DWORD)类型。数值设置为30 ~ 60 之间即可。已经设置为30,需要重启。
2.修改配置文件,增加如下的行(这里需要注意在编程时,进行数据更新时再连接数据库,否则会导致数据库连接莫名到期关闭)
#指定一个请求的最大连接时间,对于4GB左右内存的服务器可以设置为5-10。 wait_timeout = 10
3.清理本地地址为 127.0.0.1:3306 的 TCP 连接
a.查看连接状态的windows 命令行命令,该命令可以同时获得 pid
>netstat -nao
b. 清理本地地址为 127.0.0.1:3306 的 TCP 连接的python 脚本,在windows命令行下运行该脚本。
(记得先保存所有正在编辑的文件)
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 24 08:20:22 2016
"""
import os
def execCmd(cmd):
#获取windows 下cmd命令的返回结果
r = os.popen(cmd)
text = r.read()
r.close()
return text
#test
r = execCmd('netstat -ano')
def get_pid_refer_127001():
#获取和127.0.0.1 相关的pid列表
r_text = execCmd('netstat -ano')
PID_List =[]
positionFind127 = 0 # find 127.0.0.1 的结果初始化,没有找到返回 -1
positionFindReturn = 0 # find \n 换行位置的结果初始化,没有找到返回 -1
while positionFind127 != -1:
positionFind127 = r_text.find('127.0.0.1',positionFind127)
if positionFind127 !=-1:
positionFindReturn = r_text.find('\n',positionFind127)
if positionFindReturn != -1: #
#假定pid 最大位数为 8位
PID_List.append(int(r_text[positionFindReturn-8:positionFindReturn]))
positionFind127 = positionFindReturn
else:
positionFind127 = -1
return list(set(PID_List))
#对数据进行进一步的处理
#test
#d = get_pid_refer_127001()
def taskkill_pid_127001():
#根据 pid 列表杀死和 127.0.0.1 连接相关的进程
PID_List = get_pid_refer_127001()
print('pid list:',PID_List)
for PID in PID_List:
cmd = 'TASKKILL /PID ' + str(PID) + ' /F'
try:
r = os.popen(cmd)
print(cmd)
print(r)
except:
print('无法执行命令',cmd)
#test
taskkill_pid_127001()