MySQL 连接器:无法处理参数,无法删除行

MySQL Connector : could not process parameters can't delete rows

我无法使用执行方法

conn = connect(**cinfo)
cursor = conn.cursor()
# Drop the tables.
drop_query = 'DELETE FROM %s;'
tables = ['History', 'Product', 'Category']
for table in tables:
    cursor.execute(drop_query, (table,))
conn.commit()

我有这个错误:

Failed executing the operation; Could not process parameters

编辑: 我想删除这些表的所有行

尝试 TRUNCATE。它将删除给定 table 中的所有行。这就是 MySQL Documentation 提到的内容。

TRUNCATE TABLE empties a table completely. It requires the DROP privilege. Logically, TRUNCATE TABLE is similar to a DELETE statement that deletes all rows, or a sequence of DROP TABLE and CREATE TABLE statements.

conn = connect(**cinfo)
cursor = conn.cursor()
# Drop the tables.
drop_query = "TRUNCATE TABLE {};"
tables = ['History', 'Product', 'Category']
for table in tables:
    cursor.execute(drop_query.format(table))
conn.commit()
conn.close()

有关详细信息,您也可以阅读这篇 How to Delete All Rows of a MySQL Table in Python 文章。使用 format.

的字符串连接
conn = connect(**cinfo)
cursor = conn.cursor()
# Drop the tables.
drop_query = "DELETE FROM {};"
tables = ['History', 'Product', 'Category']
for table in tables:
    cursor.execute(drop_query.format(table))
conn.commit()
conn.close()