MySQLdb Module Python error



>我有一个对象的方法,它读取数据库中存在的所有表并返回查询的结果。

def get_tables(self):
    self.__cursor.execute('SELECT table_name FROM information_schema.tables where table_schema="{}";)'.format(self.__database))
    query_result = self.__cursor.fetchall()
    if not self.__cursor.rowcount:
        return False
    else:
        return query_result

该方法是从它调用的:

query_result = get_tables()
for record in query_result:
    print record[0]

当我执行脚本时,我在控制台中看到我想要的结果,最后出现此错误:

Exception _mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1") in <bound method Cursor.__del__ of <MySQLdb.cursors.Cursor object at 0x7fbd06161910>> ignored

我该如何解决?

你的SQL坏了:

... table_schema="{}";)

删除尾随)

最新更新