pymy创建数据库

创建数据库

import pymysql
db = pymysql.connect('localhost', 'root', '123456', 'heimdall')
cursor = db.cursor()

-判断EMPLOYEE表是否存在,存在就删除
cursor.execute('DROP TABLE IF EXISTS EMPLOYEE')

-创建数据库的sql语句
sql = 'CREATE TABLE employee( id int not null, name char(20), sex char(1) )'
cursor.execute(sql)

-关闭连接
db.close()

posted @ 2020-06-25 12:59  bibicode  阅读(225)  评论(0)    收藏  举报