python
复制代码
#!/usr/bin/env python
# coding=utf-8
import pymysql
# Python 连接MySQL-本地测试
def main():
# 1.设置连接
db = pymysql.connect(
host='localhost',
port=3306,
user='root',
password='123456',
db='test',
charset='utf8')
#2. 游标
cursor = db.cursor()
# 3.写sql语句
sql = "update test.user set name='吴老师' where age=26"
#4. 解析sql语句
cursor.execute(sql)
# 5.提交
db.commit()
if __name__ == '__main__':
main()
python
复制代码
#!/usr/bin/env
# coding=utf-8
import pymysql
# Python 连接MySQL-本地测试
def main():
# 1.设置连接
db = pymysql.connect(
host='localhost',
port=3306,
user='root',
password='123456',
db='test',
charset='utf8')
#2. 游标
cursor = db.cursor()
# 3.写sql语句
sql = "INSERT INTO user (name,age)VALUES('Jack','150')"
#4. 解析sql语句
cursor.execute(sql)
# 5.提交
db.commit()
if __name__ == '__main__':
main()
python
复制代码
#!/usr/bin/env
# coding=utf-8
import pymysql
# Python 连接MySQL-本地测试
def main():
# 1.设置连接
db = pymysql.connect(
host='localhost',
port=3306,
user='root',
password='123456',
db='test',
charset='utf8')
#2. 游标
cursor = db.cursor()
# 3.写sql语句
list1 = []
# 列表同时添加多个值,结果为列表
list1.extend([imsi,twoLevelCustId,twoLevelCustName, iccid, operatorsId, operatorsName, msisdn,tradeId,apnName,apnState,totalFlow,poolId,insert_time])
sql_insert = "replace into test.simcard_lenovo_life_cycle_dtl(imsi,twoLevelCustId, twoLevelCustName, iccid, operatorsId,operatorsName,msisdn,tradeId,apnName,apnState,totalFlow,poolId,insert_time)value(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
#4. 解析sql语句
cursor.execute(sql_insert,list1)
# 5.提交
db.commit()
if __name__ == '__main__':
main()