#password填自己mysql的密码 import pymysql con=pymysql.connect(host='localhost',port=3306,passwd='123456',charset='utf8',user='root') cursor=con.cursor() #建库 sql=''' create database if not exists cov2019_data ''' cursor.execute(sql) cursor.close() con.close() con=pymysql.connect(host='localhost',port=3306,passwd='123456',charset='utf8',user='root',db='cov2019_data') cursor=con.cursor() #切换数据库 cursor.db='cov2019_data' #建表 sql='''create table if not exists outsideSummary (time char(20), confirmed int(10), died int(10), curConfirm int(10), cured int(10), confirmedRelative int(10), curedRelative int(10), diedRelative int(10), curConfirmRelative int(10), primary key(time) )''' cursor.execute(sql) sql='''create table if not exists insideSummary (InsertTime char(20) ,mapLastUpdatedTime char(20),confirmed int(10),died int(10),cured int(10),asymptomatic int(10),asymptomaticRelative int(10), unconfirmed int(10),relativeTime int(10),confirmedRelative int(10),unconfirmedRelative int(10), curedRelative int(10),diedRelative int(10),icu int(10),icuRelative int(10),overseasInput int(10), unOverseasInputCumulative int(10),overseasInputRelative int(10),unOverseasInputNewAdd int(10), curConfirm int(10),curConfirmRelative int(10),icuDisable int(10), primary key(InsertTime,mapLastUpdatedTime) )''' cursor.execute(sql) sql='''create table if not exists insideProvince (area char(10),relativeTime char(20),died int(10),confirmed int(10),crued int(10),confirmedRelative int(10), diedRelative int(10),curedRelative int(10),asymptomaticRelative int(10), asymptomatic int(10),curConfirm int(10),curConfirmRelative int(10),icuDisable int(10), primary key(area,relativeTime) )''' cursor.execute(sql) sql='''create table if not exists insideCity (province char(10),city char(10),confirmed int(10),died int(10), crued int(10),confirmedRelative int(10),relativeTime char(20),cityCode int(10), primary key(city,province,relativeTime,cityCode) )''' cursor.execute(sql) sql='''create table if not exists outsideCountry ( area char(20),relativeTime char(20), confirmed int(10), died int(10),crued int(10), confirmedRelative int(10), curConfirm int(10), icuDisable int(10), primary key(area,relativeTime) ) ''' cursor.execute(sql) sql='''create table if not exists allNews (eventDescription char(200), eventTime char(20), eventUrl char(200), siteName char(20), primary key(eventDescription,eventTime,eventUrl,siteName) ) ''' cursor.execute(sql) cursor.close() con.close()