mysql - How to check if a table exists using python? -
i want check whether table exists or not before inserting data. have tried:
def checktables(tablename): stmt = "show tables %s"%tablename cursor.execute(stmt) result = cursor.fetchone() return result
but gives me error saying:
you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'ctg_payload3' @ line 1
maybe not best way.
as opinion, show tables;
, search result.
and, cannot execute show tables tablename;
, no syntax that.
edit 1
if must in sql, use
show table status 'table_name';
'
needed sql.
Comments
Post a Comment