1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import pymysql
db = pymysql.Connect( host="192.168.1.123", port=3306, user="root", password="Dp330651!", db="taobao", charset="utf8" )
cur = db.cursor() sql = 'select * from sale_data where 位置 in(%s,%s,%s)' cur.execute(sql, ("江苏", "浙江", "上海")) result = cur.fetchall() for item in result: print(item)
sql = 'delete from sale_data where 价格 < 100' cur.execute(sql) db.commit()
sql = 'update sale_data set 位置=%s where 位置 in (%s,%s,%s)' cur.execute(sql,("江浙沪","江苏", "浙江", "上海")) db.commit()
sql = 'insert into sale_data(宝贝,价格,成交量,卖家,位置) values(%s,%s,%s,%s,%s)' cur.execute(sql,("2017夏季妈妈装 40-50 岁中老年女装连衣裙",298,10000,"xxx 天猫旗舰店","北京")) db.commit()
cur.close() db.close()
|