import MySQLdb
conn = MySQLdb.connect(host='127.0.0.1', user='root',passwd='root',db='bbc',port=3306,charset = 'utf8')
# 连接数据库
cursor=conn.cursor()
# 创建游标 相当于指针
# sql_insert="insert into student values(4,'李科',2)" #sql语句插入一行新值
# sql_update="update student set id=10 where id=1" #更新,改变
# sql_delete="delete from student where id=2" #删除
# sql_select="select * from student" #选择
# sql_select_local="select id,name from student" #选择
# sql_select="select * from admin"
# SQL语句
#cursor.execute(sql_select)
# 让游标执行SQl语句
# print(cursor.fetchall())
# 打印出游标查询出表的信息
# sql_insert="insert into admin values(10,'李科',2,1,1,1,1,1,1,1)"
# 插入全部字段
sql_insert="insert into admin (username,password,secret_key) values('插入成功',123,321)"
# 插入部分字段
cursor.execute(sql_insert)
cursor.close()
# 关闭游标连接
#转载来自:https://blog.csdn.net/qq_40527086/article/details/82774789?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522159711538819724848305278%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=159711538819724848305278&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v3~pc_rank_v3-11-82774789.pc_ecpm_v3_pc_rank_v3&utm_term=python+Mysqldb&spm=1018.2118.3001.4187