找回密码
 立即注册
搜索
查看: 182|回复: 0

创建Mysql数据库数据表

[复制链接]

27

主题

30

回帖

194

积分

管理员

积分
194
发表于 2026-6-7 21:40:21 | 显示全部楼层 |阅读模式
import pymysql
db = pymysql.connect(
    host = "localhost",
    user = "root",
    password = "******",
    database = "studyPython",
    charset = "utf8mb4"
)
cursor = db.cursor()
cursor.execute("DROP TABLE IF EXISTS books")
sql = """
CREATE TABLE books(
    id int(8) NOT NULL AUTO_INCREMENT,
    name varchar(50) NOT NULL,
    category varchar(50) NOT NULL,
    price decimal(10,2) DEFAULT NULL,
    publish_time date DEFAULT NULL,
    PRIMARY KEY (id)
)ENGINE = InnoDB AUTO_INCREMENT = 1 DEFAULT CHARSET = utf8;
"""
cursor.execute(sql)
db.close

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|老村长论坛

GMT+8, 2026-7-28 00:53 , Processed in 0.037538 second(s), 20 queries .

Powered by Discuz! X5.0

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表