python操作数据之插入数据
import pymysql
def insert(sql):
"""
插入数据
"""
con = pymysql.connect(
host="********",
port=3306,
user="root",
password="*****",
database="******",
charset='utf8'
) # 链接数据库
cur = con.cursor() # 获取游标
# cur.execute("CREATE TABLE IF NOT EXISTS \
# plan(Id INT PRIMARY KEY AUTO_INCREMENT, Name VARCHAR(25))")
cur.execute(sql) #插入数据
con.commit() # 提交数据
cur.close() # 关闭游标
con.close() # 关闭链接
if __name__=='__main__':
sql = "insert into plan(instance, plan) values ('*****','*****')"
insert(sql)