使用字符串作为查询的python mysql问题

mik*_*ike 1 python mysql mysql-error-1064

所以我正在我的程序中,我有一个字符串,其中包含我想用于在数据库中插入行的查询:

query = '"INSERT INTO new_test (test_name, IP, test_run_date, results_query_time, run_time) VALUES (%s, %s, %s, %s, %s)", ("new_test", "192.168.17.194", "143917160811", "12.4847829342", "46.1268320084")'
Run Code Online (Sandbox Code Playgroud)

但是,当我执行命令时:

cursor.execute(query)
Run Code Online (Sandbox Code Playgroud)

我收到这个错误

ProgrammingError:(1064,'你的SQL语法有错误;请查看与你的MySQL服务器版本相对应的手册,以便在\'附近使用正确的语法.'INSERT INTO new_test(test_name,IP,test_run_date,results_query_time,run_tim \'在第1行')

我尝试了一些其他的引用组合,但我不能为我的生活弄清楚我做错了什么.有任何想法吗?谢谢!

cwa*_*ole 5

"在查询开头有一个额外的.这肯定会打破它.看起来你想要:

# notice the extra ' around the %s
query = """INSERT INTO new_test 
              (test_name, IP, test_run_date, results_query_time, run_time) 
           VALUES ('%s', '%s', '%s', '%s', '%s')""" % \
           ("new_test", "192.168.17.194", "143917160811", 
           "12.4847829342", "46.1268320084")
Run Code Online (Sandbox Code Playgroud)