查询时出现MySQL语法错误,有什么不对

时间:2021-04-10 00:08:30

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; 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

SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在'usage(id BIGINT AUTO_INCREMENT,use_date datetime,ctn VARCHAR(255),destinatio'第1行附近使用正确的语法。失败的查询:“CREATE TABLE用法(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“。失败的查询:CREATE TABLE用法(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

It says near and then gives me about 30 characters !

它说近,然后给我约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 !

我敢肯定,很明显为什么它不适合那些没有撕掉头发10分钟的人 - 有人请我摆脱我的痛苦!

1 个解决方案

#1


3  

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.

此外,虽然它确实给了你很大一部分查询,但它是最重要的第一部分...它说'使用率接近通常是它有问题。

#1


3  

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.

此外,虽然它确实给了你很大一部分查询,但它是最重要的第一部分...它说'使用率接近通常是它有问题。