python---连接MySQL第四页

python缓存结果集式的cursor可以用来提高性能。

例子:

#!conding:utf-8
from mysql.connector import errorcode
import mysql.connector

cnx=None
cursor=None
try:
    cnx = mysql.connector.connect(host='192.168.1.201',port=3306,user='admin',password='131417')
    cursor=cnx.cursor(buffered=True)#buffered=True会把结果集保存到本地,这样可以提高性能
    cursor.execute('select * from studio.t where id=7')
    for x in cursor:
        print x

except mysql.connector.Error,err:
    print err

finally:
    if cursor is not None:
        cursor.close()
        cnx.close()

 

posted on 2015-11-05 12:54  蒋乐兴的技术随笔  阅读(243)  评论(0编辑  收藏  举报

导航