import pymysql #创建连接 con = pymysql.connect(host='localhost',user='root',password='123456',port=3306,database='zhy') #创建游标对象 cur = con.curson() #编写查询的sql语句 sql = 'select * from t_student' try: cur.execute(sql) print(查询成功) students = cur.fetchall() print(students) except Exception as