我无法使用 mysql-connector-python(python 版本 3.5)查询 mysql 数据库。我正在尝试为整个站点列表提取特定日期时间范围的 air_temperature 。第一个 stn 的第一个查询工作得很好,但第二个只是永远挂起。
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()