import pymysql
# 1.连接
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='', db='111', charset='utf8')
# 2.创建游标
cursor = conn.cursor()
#注意%s需要加引号
sql = "select * from user"
# 3.执行sql语句
cursor.execute(sql)
for i in cursor.description: # 查询出字段
print(i)
result=cursor.execute(sql) #执行sql语句,返回sql查询成功的记录数目
print(result)
a = cursor.fetchall() # 查询出数据
print(a)
conn.close()