Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python MySQL查询抛出1064错误_Python_Mysql_Sql_Flask - Fatal编程技术网

Python MySQL查询抛出1064错误

Python MySQL查询抛出1064错误,python,mysql,sql,flask,Python,Mysql,Sql,Flask,我有一个巨大的数据存储在mysql数据库中。数据库中的一列是长字符串。其中一个字符串是“iEdge检测到“警告”条件“iEdge it”,它存储在字符串类型中。我必须查询数据库并找出有多少这样的字符串。我是从我的python程序中查询的。当我用这样的方法做的时候 cur.execute("select count(*) from table1 as tmp where tmp.err_string='"+row[r]+"'") 行[r]包含“iEdge检测到“警告”条件“iEdge it”

我有一个巨大的数据存储在mysql数据库中。数据库中的一列是长字符串。其中一个字符串是“iEdge检测到“警告”条件“iEdge it”,它存储在字符串类型中。我必须查询数据库并找出有多少这样的字符串。我是从我的python程序中查询的。当我用这样的方法做的时候

  cur.execute("select count(*) from table1 as tmp where tmp.err_string='"+row[r]+"'")
行[r]包含“iEdge检测到“警告”条件“iEdge it”

我收到错误1064(您的SQL语法有错误…)。我认为这是因为字符串中有一些引号。我可以知道如何解决这个问题吗?

你能试试这个吗:

sql = "select count(*) from table1 as tmp where tmp.err_string=%s"
cursor.execute(sql, [row[r]])
让MySQL Python库担心转义特殊字符以及如何引用字符串


有关详细信息,请参阅。

包括您的确切查询,也许我们可以帮助您。如果您希望转义单引号,请将其加倍。@TimBiegeleisen Include谢谢。在cursor.execute()中,第二个参数应该是iterable对象。所以我把它改为cursor.execute(sql[row[r]])