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()

浙公网安备 33010602011771号