python-6.7

import pymysql
db=pymysql.connect(host='localhost',user='root',password='root',db='mysql')
cursor=db.cursor()
# sql='''create table student(sno char(10),sname varchar(20),primary key(sno))
# default charset=utf8;'''
# cursor.execute(sql)
#修改表结构
# add_sql='''alter table student add column ssex varchar(1),add column sage int;'''
# cursor.execute(add_sql)
# #删除性别列
# delete_sql='''alter table student drop column sage;'''
# cursor.execute(delete_sql)

# cursor.execute('show table;')
# print(cursor.fetchall())
# cursor.close()
import pymysql
db=pymysql.connect(host='localhost',user='root',password='root',db='mysql')
cursor=db.cursor()
#插入一条数据
# insert_sql='''insert into student values('2022001','ll','male')'''
# cursor.execute(insert_sql)
#插入多条数据
# insert_many_sql='''insert into student values('2022003','lc','女'),
# ('2022004','xiaomi','男')'''
# cursor.execute(insert_sql)
# insert_many_sql=[('2022003','lc','女'),('2022004','xiaomi','男')]
# cursor.executemany('insert into student values(s%,s%,s%);',insert_many_sql)
#提交到数据库
# db.commit()
# cursor.execute('select * from student')
# print(cursor.fetchall())
# cursor.close()

 

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

昵称

取消
昵称表情

    暂无评论内容