Python之连接MySQL数据库,执行建表语句

import pymysql

db=pymysql.connect('localhost','root','password','database_name')

cursor=db.cursor()

cursor.execute('drop table if EXISTS class')

sql='''create table class(
id int not null PRIMARY KEY auto_increment,
first_name char(20) NOT NULL ,
last_name CHAR (20),
age INT,
sex CHAR (1),
income FLOAT )
'''
cursor.execute(sql)

db.close()

猜你喜欢

转载自www.cnblogs.com/feigebaqi/p/9237611.html
今日推荐