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()
posted @ 2018-06-28 10:55  飞哥霸气  阅读(345)  评论(0编辑  收藏  举报