http://www.shsnc.com/show-109-1004-1.html
import pymysql def insert_sql(sql): eng = pymysql.connect(host='123.56.2.32', user='root', password='123456', port=3306,db = 'my_f') cursor = eng.cursor() cursor.execute(sql) # data = cursor.fetchone() # data = cursor.fetchall()se eng.commit() eng.close() return True import json data=json.dumps({"username":"admin","passwork":"admin"}) print(data) ex_sql="insert into task(data_,name) values ('%s','123456')"%data # json 字段 name 其他字段 insert_sql(ex_sql)