简体   繁体   English

查询时出现MySQL语法错误,出了什么问题

[英]MySQL Syntax error on query, what's wrong

I am going out of my mind here ... I am an SQL beginner .. but I cannot for the life of me see what is wrong with my statement : 我在这里疯了……我是SQL初学者..但是我一生都看不到我的语句出了什么问题:

CREATE TABLE usage 
  (id BIGINT AUTO_INCREMENT
  , use_date datetime 
  , ctn VARCHAR(255)
  , destination VARCHAR(255)
  , cost_type BIGINT
  , cost BIGINT
  , up_data bigint
  , down_data bigint
  , INDEX cost_type_idx (cost_type)
  , PRIMARY KEY(id) ) ENGINE = INNODB;

Here is the error thrown by MySQL (Version 5.5.8) 这是MySQL(版本5.5.8)引发的错误

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'usage (id BIGINT AUTO_INCREMENT, use_date datetime, ctn VARCHAR(255), destinatio' at line 1. Failing Query: "CREATE TABLE usage (id BIGINT AUTO_INCREMENT, use_date datetime, ctn VARCHAR(255), destination VARCHAR(255), cost_type BIGINT, cost BIGINT, up_data bigint, down_data bigint, INDEX cost_type_idx (cost_type), PRIMARY KEY(id)) ENGINE = INNODB". Failing Query: CREATE TABLE usage (id BIGINT AUTO_INCREMENT, use_date datetime, ctn VARCHAR(255), destination VARCHAR(255), cost_type BIGINT, cost BIGINT, up_data bigint, down_data bigint, INDEX cost_type_idx (cost_type), PRIMARY KEY(id)) ENGINE = INNODB 在第1行中,检查与MySQL服务器版本相对应的手册,以找到在'用法(id BIGINT AUTO_INCREMENT,use_date datetime,ctn VARCHAR(255),destinatio')附近使用的正确语法。失败的查询:“创建表的用法(id BIGINT AUTO_INCREMENT ,use_date datetime,ctn VARCHAR(255),目标VARCHAR(255),cost_type BIGINT,cost BIGINT,up_data bigint,down_data bigint,INDEX cost_type_idx(cost_type),PRIMARY KEY(id)ENGINE = INNODB”。失败查询:CREATE TABLE用法(id BIGINT AUTO_INCREMENT,use_date datetime,ctn VARCHAR(255),目标VARCHAR(255),cost_type BIGINT,cost BIGINT,up_data bigint,down_data bigint,INDEX cost_type_idx(cost_type),PRIMARY KEY(id))ENGINE = INNODB

It says near and then gives me about 30 characters ! 它说near ,然后给我大约30个字符!

I have tried different column names, in case I am using a keyword. 我尝试使用不同的列名,以防我使用关键字。 I have tried different DataTypes - still no luck ! 我尝试了不同的DataTypes-仍然没有运气!

I'm sure it's very obvious why it's not working to someone who hasn't been tearing their hair out for 10 minutes - someone please put me out of my misery ! 我确信这很明显为什么对那些十分钟没有撕头发的人不起作用-有人请让我摆脱痛苦!

That error appears because USAGE is a reserved word in mysql. 出现该错误是因为USAGE是mysql中的保留字。

See: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html for a list of reserved words. 有关保留字的列表,请参见: http : //dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Also, while it did give you a big part of the query, it's the first part that is most important... It said near 'usage so that is usually what it had an issue with. 此外,尽管它确实为您提供了很大一部分查询,但它是最重要的第一部分...它near 'usage说,这通常是它所遇到的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM