标签:语句 python datetime rop port passwd arc roo pass
db = pymysql.connect(host=‘localhost‘,port =3306,user=‘root‘,passwd=‘root‘,db=‘sys‘,charset=‘utf8‘ )
在创建表时,注意是否创建过该表,如果创建过就删除
cursor.execute("drop table if EXISTS income")
SQL = """CREATE TABLE `income` ( `id` int(11) NOT NULL AUTO_INCREMENT, `datetime` varchar(20) DEFAULT NULL, `ironincome` decimal(20,2) DEFAULT NULL, `generalincome` decimal(20,2) DEFAULT NULL, `baiincome` decimal(20,2) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; """
cursor.execute(SQL)
db.close()
# -*- coding:utf-8 -*- import pymysql # 打开数据库 db = pymysql.connect(host=‘localhost‘,port =3306,user=‘root‘,passwd=‘root‘,db=‘sys‘,charset=‘utf8‘ ) #使用cursor()方法获取操作游标 cursor = db.cursor() #如果数据表已经存在使用execute()方法删除表 cursor.execute("drop table if EXISTS income") #创建数据库SQL语句 #time,ironincome,general_income,baiincome SQL = """CREATE TABLE `income` ( `id` int(11) NOT NULL AUTO_INCREMENT, `datetime` varchar(20) DEFAULT NULL, `ironincome` decimal(20,2) DEFAULT NULL, `generalincome` decimal(20,2) DEFAULT NULL, `baiincome` decimal(20,2) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; """ cursor.execute(SQL) db.close()
标签:语句 python datetime rop port passwd arc roo pass
原文地址:https://www.cnblogs.com/zsw001/p/11132776.html