1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#! /usr/bin/python3 import pymysql print("开始数据库操作") #不指定字符连接 #db = pymysql.connect("192.168.0.222","pandy","******","pandy_psi") #指定使用utf8字符来连接数据库,避免乱码问题 db = pymysql.connect(host='192.168.0.222', port=3306, user='pandy', passwd='******',db='pandy_psi',charset='utf8') cursor = db.cursor() sql="SELECT CLIENT_ID,NAME ,ADDR ,STAFF_NAME ,TEL ,MOBILE FROM PSI_CLIENT" cursor.execute(sql) list = cursor.fetchall() for row in list: print("ID=%s, NAME=%s, ADDR=%s"%(row[0],row[1],row[2])) db.close() |