import pymysql,random,datetime conn = pymysql.connect(database="wetest", user="bms", password="bms@2018", host="123.156.187.154", port=3306,charset="utf8") cursor = conn.cursor(cursor=pymysql.cursors.SSDictCursor) sql = """ select * from vul_detail """ cursor.execute(sql) while True: row = cursor.fetchone() if not row: break print(row)