我正试图找到一种方法,在多个执行中重用DB连接。但是,在执行第二个db.cursor()时,我会得到错误:
mysql.connector.errors.OperationalError: MySQL连接不可用。
import mysql.connector
db = mysql.connector.connect(host="***", user="***", password="***", database="***")
db.autocommit = True
cursor = db.cursor()
cursor.execute("call procedure1();")
rows1 = cursor.fetchall()
cursor = db.cursor()
cursor.execute("call procedure2()")
rows2 = cursor.fetchall()发布于 2019-06-21 07:36:49
你必须打开多个连接。MySQL是线程安全的,您可以让两个线程共享相同的连接,多个线程不能在同一连接上同时向MySQL服务器发送查询,因此每个连接将能够访问各自的游标、查询和结果集,而不会对其他连接产生影响,但是每个线程或进程都需要自己的连接。
https://stackoverflow.com/questions/51660537
复制相似问题