pymysql查询


from pymysql import connect


# 创建Connection连接
conn = connect(host='localhost',port=3306,database='df',user='root',password='mysql',charset='utf8')
# 获得Cursor对象
curson = conn.cursor()

count = curson.execute('select * from goods;');
print('查询到%d条数据'%count)
print(curson.fetchone())
#打印一条
print(curson.fetchmany())
#元祖里面包的元祖,就一条数据
print(curson.fetchmany(3))
#传参数,传几取几条
print(curson.fetchall())
#全部取

line_count = curson.fetchone()
print(line_count)
print(line_count[0])
print(line_count[1])
print(line_count[2])
#可以把一条语句里面的东西,一段一段的取出来


# 关闭Cursor对象
curson.close()
# 关闭Connection对象
conn.close()

你可能感兴趣的:(pymysql查询)