Minor problems encountered during mysql operations

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.