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='')
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()
上一篇:zoj 2818 Root of the Problem(数学思维题)


下一篇:iOS 定时器的比较