import pymysql
#需求:在world数据库中,创建一张student表
#1.连接数据库
db=pymysql.connect(host='localhost',user='root',passwd='123456789',db='world')
#创建一个游标对象
cursor=db.cursor()
#执行sql语句.create table student
SQL='''create table yxj(sID char(10),name varchar(20),phone char(11),Dnumber char(4),primary key(sID))default charset=utf8;'''
cursor.execute(SQL)
#显示出创建的表
cursor.execute('show tables;')
#重点:fetchall()显示出所有的结果
# print(cursor.fetchone())
# print(cursor.fetchone())
# print(cursor.fetchall())
data=cursor.fetchall()
for i in data:
print(i)
© 版权声明
THE END
暂无评论内容