Skip to content

Instantly share code, notes, and snippets.

@wilkice
Created September 3, 2021 09:55
Show Gist options
  • Select an option

  • Save wilkice/daa21f14b3866e0451ced10039a3e9a0 to your computer and use it in GitHub Desktop.

Select an option

Save wilkice/daa21f14b3866e0451ced10039a3e9a0 to your computer and use it in GitHub Desktop.
[pymysql usage] #python
import pymysql
db = pymysql.connect(host="192.168.236.111", user="fakeuser", password="fakepassword",port=xxx, db="xxx")
data = {
"a": 1,
"b": "2,3"
}
table_name="detail"
column_string = ','.join(data.keys())
value_string = ','.join([f'%({key})s' for key in data.keys()])
sql = f'INSERT IGNORE INTO {table_name} ({column_string}) VALUES ({value_string})'
print(sql)
cursor = db.cursor()
cursor.execute(sql, data)
db.commit()
@lzc978
Copy link

lzc978 commented Sep 9, 2021

gist域名可以直连了~

@wilkice
Copy link
Author

wilkice commented Sep 10, 2021

gist域名可以直连了~

哈哈,不错不错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment