pymysql模块,python与MySQL之间的交互
import pymysql db = pymysql.connect(host="192.168.137.1", port=3306, user="wu", password="123456", db="爸爸测试", charset="utf8") #这是个坑啊utf-8没有- # cursor = db.cursor() # sql = "select * from boy" # 这是一个坑,拼接字符串的坑 # sql = "select * from t1 where user = %s and pwd = %s" # return_value = cursor.execute(sql,("wu","sda")) # sql = "insert into boy(name,age) values(%s,%s)" # return_value = cursor.execute(sql,("老九",1)) # return_value = cursor.executemany(sql,[(),(),()]) cursor = db.cursor(pymysql.cursors.DictCursor) #传参,输出结果为字典 # print(cursor.lastrowid) 插入的时候看光标 sql = "select * from boy" return_value = cursor.execute(sql) print(cursor.fetchone()) # cursor.scroll(3,mode="relative") cursor.scroll(0,mode="absolute") print(cursor.fetchall()) # result = cursor.fetchall() # # print(db) # print(return_value) # print(result) db.commit() cursor.close() db.close()
-----------------------------------------------------------------------------------------------------------------------------------------