import pymysql conn = pymysql.connect(host='127.0.0.1',port=3306,user='root',\ passwd='123456',db='lesson54') cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) # sql ='create table test(id INT ,name varchar (20))' # cursor.execute(sql) # cursor.execute('insert into test values (1,"alex"),(2,"xis")') cursor.execute('select * from test') # 获取数据 # print(cursor.fetchone()) # print(cursor.fetchmany(2)) print(cursor.fetchall()) # 移动光标位置 cursor.scroll(-1,mode='relative') #相对定位 cursor.scroll(1,mode='absolute') #绝对定位 conn.commit() cursor.close() conn.close()