1 Star 0 Fork 19

小春/Python_Learning

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
table.py 616 Bytes
一键复制 编辑 原始数据 按行查看 历史
阿基米东 提交于 2020-09-10 20:44 +08:00 . pymysql
import pymysql
# 打开数据库连接
db = pymysql.connect(host="localhost",user="root",password="",db="test",charset="utf8")
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
# 如果数据表已经存在使用 execute() 方法删除表
cursor.execute("DROP TABLE IF EXISTS USER")
# 创建数据表SQL语句
sql = """CREATE TABLE IF NOT EXISTS USER (
id int unsigned not null auto_increment PRIMARY KEY,
name varchar(32) not null unique,
email varchar(100),
cdate datetime );"""
cursor.execute(sql)
# 关闭数据库连接
db.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/wython/Python_Learning.git
git@gitee.com:wython/Python_Learning.git
wython
Python_Learning
Python_Learning
master

搜索帮助