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()
© 版权声明
THE END
暂无评论内容