python---连接MySQL第四页
时间:2021-07-01 10:21:17
帮助过:2人阅读
!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()
python---连接MySQL第四页
标签: