pymsql操作mysql的方式
#导入模块 import pymysql#创建连接
conn = pymysql.connect(host='localhost',port=3306,user='kk',passwd='123',db='pysqltest')
#创建游标
course = conn.cursor()
#执行sql
插入表
row1 = course.execute("create table t1(id int auto_increment PRIMARY KEY ,name VARCHAR (32) not NULL )")
插入多天数据用executemany这个函数,后面用列表
# row2 = course.executemany("insert into t1 (name) VALUES (%s)",[("kk"),("gg")])
更新表,这个会把name一列全部修改为www
# row3 = course.execute("update t1 set name='www'")
条件修改,只把后面的id=1的修改
row4 = course.execute("update t1 set name='ee' WHERE> #提交到数据库
conn.commit()
#关闭游标
course.close()
#关闭数据库连接
conn.close()
页:
[1]