mysql连接器python在游标上的循环非常慢
我无法使用mysql连接器python(python版本3.5)查询mysql数据库。我正试图找出整个电台列表中特定日期时间范围内的气温。第一个stn的第一个查询工作正常,但第二个查询永远挂起mysql连接器python在游标上的循环非常慢,python,mysql,mysql-connector-python,Python,Mysql,Mysql Connector Python,我无法使用mysql连接器python(python版本3.5)查询mysql数据库。我正试图找出整个电台列表中特定日期时间范围内的气温。第一个stn的第一个查询工作正常,但第二个查询永远挂起 import mysql.connector import datetime connection = mysql.connector.connect(host=' ', user=' ', passwd='
import mysql.connector
import datetime
connection = mysql.connector.connect(host=' ',
user=' ',
passwd=' ',
database=' ',
port= )
stn_id = [‘stn_01’,’stn_02’, ’stn_03’, ’stn_04’, ’stn_05’]
datetime_start = datetime.datetime(2016, 1, 1, 00, 00, 00)
datetime_end = datetime.datetime(2016, 2, 1, 00, 00, 00)
for stn in range(0,n_stn,1):
cursor = connection.cursor(buffered=True)
q = """
SELECT time_stamp, air_temperature
FROM %s
WHERE time_stamp >= %s
AND time_stamp <= %s
"""
cursor.execute(q,(stn_id[stn], datetime_start, datetime_end))
temp_results = cursor.fetchall()
# do something with the results
cursor.close()
导入mysql.connector
导入日期时间
connection=mysql.connector.connect(主机=“”,
用户=“”,
passwd=“”,
数据库=“”,
端口=)
stn_id=['stn_01'、'stn_02'、'stn_03'、'stn_04'、'stn_05']
datetime_start=datetime.datetime(2016,1,1,00,00,00)
datetime_end=datetime.datetime(2016,2,1,00,00,00)
对于范围内的stn(0,n_stn,1):
游标=连接。游标(缓冲=真)
q=”“”
选择时间戳、空气温度
来自%s
其中时间戳>=%s
时间戳尝试将行cursor=connection.cursor(buffered=True)
移动到for循环之外。另外,在stn\u id中将您的循环用作stn中的,这会更像python