1.插入数据
2.更新数据
进阶:遍历表,插入,并更新数据
import time
import pymysql
conn= pymysql.connect(
host='localhost',
port = 3306,
user='root',
passwd='154524',
db ='test',
)
cur = conn.cursor()
#插入一条数据
cur.execute("insert into student values('5','8om','3 year 2 class','9')")
#修改查询条件的数据
cur.execute("update student set class='3 year 1 class' where name = 'Tom'")
cur.execute('select ssh from {}'.format("pro_test"))
#遍历表的数据,读取并更新
list = [] ## 空列表
for promsg in cur:
ssh_url=promsg[0]
print(ssh_url)
upadtemsg="update pro_test set url='"+http_url+"' where ssh ='"+ssh_url+"'"
list.append(upadtemsg)
for item in list :
cur.execute(item)
cur.close()
conn.commit()
conn.close()
参考文章:python连接数据库
通过mysqlclient操作MySQL数据库



