【MySQL与python交互】02 创建数据库表

import pymysql
'''
execute
英 [ˈeksɪkjuːt]   美 [ˈeksɪkjuːt]  
v.
(尤指依法)处决,处死;实行;执行;实施;成功地完成(技巧或动作)
'''

db = pymysql.connect('本机ip', 'root', 'root', 'aimei')
# 创建一个cursor对象
cursor = db.cursor()

# 检查表是否存在,如果存在则删除
# 代码创建表比较少
cursor.execute('drop table if exists bandcard')

# 建表
sql = 'create table bandcard(id int auto_increment primary key,money int not null)'
cursor.execute(sql)

# 断开
cursor.close()
db.close()


发布了112 篇原创文章 · 获赞 114 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_38114487/article/details/105479509