import pymysql
# 创建数据库表
db = pymysql.connect("localhost", "root", "wsw..177122", "wakey")
cursor = db.cursor()
sql = 'show tables;'
cursor.execute(sql)
data = cursor.fetchall() # 查看所有结果
print(data)
sql = 'select * from student;'
cursor.execute(sql)
data = cursor.fetchone()
print(data)
# 检查表是不是存在,如果存在则删除
cursor.execute("drop table if exists boy")
# 建表
sql = 'create table boy(id int auto_increment primary key, name varchar(20) not null, age int not null)'
cursor.execute(sql)
cursor.close()
db.close()