在使用 ajax 运行 mysql server 5.6 的 2008 vm 上运行我的 python 脚本时出现以下错误
Traceback (most recent call last):
File "mypythonjob.py", line 22, in <module>
db = mdb.connect('localhost', 'website','servername', 'website')
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10055)")
我可以在资源监视器中观看,因为 CPU 在大约 75 秒后爬升到 100%,此时 mysql.exe 有 30 个线程,python.exe 有 6 个线程,错误被踢出,python.exe 被终止,mysql 服务器无法访问大约 2 分钟,然后它会重新上线。
import os, datetime, pymssql , time, subprocess
import MySQLdb as mdb
today = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
sixmonth = today - datetime.timedelta(days=180)
db = mdb.connect('localhost', 'website','server', 'website') #values changed for post
cursor = db.cursor()
sql2 = "select 1column from mytable where 4column like '"+str(today)+"'" #values changed for post (query produces 1100 rows)
cursor.execute(sql2)
data2 = cursor.fetchall()
cursor.close()
db.close()
for row2 in data2:
db = pymssql.connect(host="sqldb",user="username", password="pwd", database="somedatabase") #values changed for post
cursor = db.cursor()
sql3 = "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; select col1,col2,col3 from tbl where col1 like '%somedata%' and col3 < '"+str(sixmonth)+"' and col2 ='data'" #values changed for post
cursor.execute(sql3)
data3 = cursor.fetchall()
db.commit()
cursor.close()
db.close()
for row3 in data3:
db = mdb.connect('localhost', 'website','server', 'website')
cursor = db.cursor()
sql4 = "update mytable set 2column ='"+str(row3[2])+"', 3column ='"+str(row3[1])+"' where 4column like '"+str(today)+"' and 1column like '"+str(row3[0])+"'" #values changed for post (seems to finish the update properly at 575 rows)
cursor.execute(sql4)
data4 = cursor.fetchall()
db.commit()
cursor.close()
db.close()
分辨率尝试运行代码,其中包含一小部分 10 行的起始数据与 1100 检查以确保我正在关闭连接和数据库,当我完成它们时,我检查了 mysql 日志文件,我的设置 max_allowed_packet 没有任何改变。 ini 到 32mg 然后 500mg 最后注释掉
谢谢你看
补充说明:如果我删除 SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;从第二个查询它似乎继续运行。我让它走了 5 分钟,计数停止在 575 更新并保持在那里。