我正在使用 mysql.connector 并且对于某些任务,例如在本地 mysql 数据库中插入数据,该过程需要 0.0436846 秒。平均,有什么方法可以提高吗?
import mysql.connector
from mysql.connector import errorcode
class Dal:
@profile
def __init__(self, dic):
try:
self.cnx = mysql.connector.connect(user=dic['user'],
password=dic['password'],
host=dic['host'],
database=dic['database'])
self.cursor = self.cnx.cursor()
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("User/Pass Fails")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("BD no exist")
else:
print(err)
def insert_event(self,dic):
ins_ev = ("INSERT INTO events "
"(device, type, index, datetime, c1,\
c2, vel, head, pfm, age,vod,created_on ) "
"VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
)
self.cursor.execute(ins_ev, dic)
self.cnx.commit()
也许另一种方法?