When the mysql database executes SQL statements in the program or when the SQL statement is executed, the database table may have some special characters, such #,.
The following table name backup_2014.2.22 may be faulty during query. for this reason, the error table_name = "backup_2014.2.22" is reported. For example, write self in python. db. query ("show create table % s" % table_name) [0] reports an error (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '. 22 'at line 1 ") Traceback (most recent call last): File"/Users/xuxiaodong/work/db_table_to_Wiki.py ", line 120, in <module> main (sys. argv) File "/Users/xuxiaodong/work/db_table_to_Wiki.py", line 117, in main db. get_db_tables_to_wiki () File "/Users/xuxiaodong/work/db_table_to_Wiki.py", line 31, in get_db_tables_to_wiki create_table = self. db. query ("show create table % s" % table_name) [0] TypeError: 'nonetype 'object has no attribute' _ getitem _' indicates that the SQL statement syntax is incorrect, the reason is that a syntax error occurs when the table name with special characters is directly used as a string for SQL statements. In SQL statements, the field and table name should have 'table ', these two symbols can be included in self. db. query ("show create table '% s" % table_name + "'") is a standard syntax in SQL statements.