python链接mysql数据库失败_MySQL-python连接MySQL数据库问题,总是抛异常。

系统win764位系统,Python2.7版本,同样64位,MySQL-python1.2.364位。测试代码#-*-coding:utf-8-*-importsys,MySQLdb,threading,random,timereload(sys)sys.setdefaultencoding('utf...

系统win7 64位系统,Python2.7版本,同样64位,MySQL-python1.2.3 64位。测试代码

# -*- coding: utf-8 -*-

import sys,MySQLdb,threading,random,time

reload(sys)

sys.setdefaultencoding('utf-8')

def test():

for az in range(1,100):

time.sleep(random.randint(1,5))

cur1.execute('insert into test1 (test1)values (%s)', str(random.randint(1,100)))

conn = MySQLdb.connect(host='localhost', user='test', passwd='test', db='test1')

conn.ping(True)

cur1 = conn.cursor()

th=[]

for a in range(50):

th.append(threading.Thread(target=test,args=()))

for aa in th:

aa.start()

for aaa in th:

aaa.join()

抛出的异常

Exception in thread Thread-5:

Traceback (most recent call last):

File "D:\python\lib\threading.py", line 801, in __bootstrap_inner

self.run()

File "D:\python\lib\threading.py", line 754, in run

self.__target(*self.__args, **self.__kwargs)

File "G:/source/python/test1.py", line 10, in test

cur1.execute('insert into test1 (test1)values (%s)', str(random.randint(1,100)))

File "D:\python\lib\site-packages\MySQLdb\cursors.py", line 174, in execute

self.errorhandler(self, exc, value)

File "D:\python\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler

raise errorclass, errorvalue

OperationalError: (2013, 'Lost connection to MySQL server during query')

不一定是哪个线程抛,但是都是一样的异常OperationalError: (2013, 'Lost connection to MySQL server during query')这句话,网上说的改数据库配置文件的方法都试过了,木有用。MySQL-python最新版还没有64位的,源码还编译失败、请问这个应该怎么处理?

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值