连接和获取数据
可以使用 pymysql lib;
import pymysql
from pymysql.constants import CLIENT
news_db = pymysql.connect(host='xx', port=xxx, user='xxx', passwd="xxx", db='xxx', client_flag=CLIENT.MULTI_STATEMENTS)
news_cursor = news_db.cursor()
def fetch_news_title(start_time,end_time,start_offset, batch_size):
sql = "SELECT xxxx >= '{}' and xxx<'{}' " \
"limit {}, {}".format(start_time, end_time, start_offset,batch_size)
news_cursor.execute(sql)
result = []
for row in news_cursor.fetchall():
result.append(row)
return result
网友评论