pymysql操作

import pymysql

conn_mysql = pymysql.connect(host='127.0.0.1',port=3306,user='root',password='123456',db="s3")

cur = conn_mysql.cursor()
# create_table = 'CREATE TABLE ec2(id INT , NAME VARCHAR(30) )'
#
#cur.execute(create_table) #执行sql
#
# into_data = 'insert into ec2(id,name) values(2,"B")'

# cur.execute(into_data)

cur.execute("SELECT * FROM EC2") #游标必须先查询后cur.fetchone 才能执行
print(cur.fetchone()) #打印当前游标位置的一条数据

# many=cursor.fetchmany(3) #打印当前游标位置后3条数据
# all=cursor.fetchall() #打印当前游标位置后全部数据

print(cur.fetchone())
cur.scroll(1,mode="relative") # 相对当前位置移动 当前位置如果是1 向上移动以为 如果是-1向下移动一位
print(cur.fetchone()) #上面向上移动一位 这里打印的数据就移动到上面去的数据了


cur.scroll(2,mode="absolute") # 绝对位置移动 直接移动到第二条
print(cur.fetchone())


conn_mysql.commit() #提交
cur.close()
conn_mysql.close()



猜你喜欢

转载自www.cnblogs.com/ajaxa/p/9257480.html