SSCursor (流式游标) 解决 Python 使用 pymysql 查询大量数据导致内存使用过高的问题

版权声明:Ch3nnnnnnnnnn的博客 https://blog.csdn.net/weixin_43064185/article/details/89555877
# -*- coding: utf-8 -*-
'''Chinese comments are used below, need to be added'''
# Author: xiaolong.shi
# Email: [email protected]

import GeoCode

class AddGeocode(object):

    def __init__(self):
        self.geocode = GeoCode()
        self.mismath_num = 0
        self.db = pymysql.connect(host='172.22.64.50',user='xialong',password='adiiadsjkh',db='knowledgebase',charset='utf8')
        # 流式游标
        self.cursor = self.db.cursor(cursor=pymysql.cursors.SSDictCursor)

    def modify(self):
        """
        查询省市区错乱的数据,并修改导入数据库
        """
        sql = 'SELECT * FROM kb_mall;'
        self.cursor.execute(sql)
        while True:
             row = self.cursor.fetchone()
             if not row:
                 break
             print(row)

mysql查询大数据,遍历大数据,流式查询

猜你喜欢

转载自blog.csdn.net/weixin_43064185/article/details/89555877
今日推荐