美文网首页
python mysql 操作备忘

python mysql 操作备忘

作者: NazgulSun | 来源:发表于2022-09-11 19:13 被阅读0次

连接和获取数据

可以使用 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

相关文章

网友评论

      本文标题:python mysql 操作备忘

      本文链接:https://www.haomeiwen.com/subject/cfnqortx.html