python以mysql_use_result 方式查询数据

参考:

https://blog.csdn.net/weixin_41287692/article/details/83545891

http://mysql-python.sourceforge.net/MySQLdb.html#

 

代码示例:

import pymysql
conn = pymysql.connect(host='172.16.1.10',port=3357,passwd='c123456',charset='utf8',cursorclass = pymysql.cursors.SSCursor)
cursor=conn.cursor()
cursor.execute('select * from ceshi.tt limit 10000')
result=cursor.fetchone()
while result:
    print(result[0])
    result = cursor.fetchone()
    
cursor.close()
conn.close()

缺点:无法维持长连接,读取后要尽快处理。

posted on 2022-03-17 00:30  柴米油盐酱醋  阅读(95)  评论(0编辑  收藏  举报

导航