python-pymysql

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)

 

温馨提示:本文最后更新于2024-06-06 09:00:41,某些文章具有时效性,若有错误或已失效,请在下方留言或联系站长
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情

    暂无评论内容