注意此坑,字符串需要加引号,'%s'

conn = pymysql.connect("10.60.119.79", "user", "password", "database_name", charset='utf8')

insert_sql = "INSERT INTO Device (Column1, Column2, Column3) VALUES ('%s', '%s', '%s');" % (value1, value2, value3)
print insert_sql
cur = conn.cursor()

cur.execute(insert_sql)

conn.commit()
cur.close()
conn.close()


↙↙↙阅读原文可查看相关链接,并与作者交流