python---连接MySQL第三页

用python语言从MySQL中查询数据

#!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()
    cursor.execute('select * from studio.t where id=%s',(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:42  蒋乐兴的技术随笔  阅读(252)  评论(0编辑  收藏  举报

导航