-
-
Save wilkice/daa21f14b3866e0451ced10039a3e9a0 to your computer and use it in GitHub Desktop.
[pymysql usage] #python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
gist域名可以直连了~