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

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

python - Error: Unresolved reference 'selenium' What is the reason? -

asp.net ajax - Jquery scroll to element just goes to top of page -