问题 错误1064(42000):您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以获得正确的语法


当我试图在我的表中插入一行时,我收到以下错误:

ERROR 1064 (42000): 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 ''filename') 
VALUES ('san', 'ss', 1, 1, 1, 1, 2, 1, 1, 'sment', 'notes','sant' at line 1

请帮帮我。

mysql> desc risks;
+-----------------+--------------+------+-----+---------------------+----------------+
| Field           | Type         | Null | Key | Default             | Extra          |
+-----------------+--------------+------+-----+---------------------+----------------+
| id              | int(11)      | NO   | PRI | NULL                | auto_increment |
| status          | varchar(20)  | NO   |     | NULL                |                |
| subject         | varchar(100) | NO   |     | NULL                |                |
| reference_id    | varchar(20)  | NO   |     |                     |                |
| location        | int(11)      | NO   |     | NULL                |                |
| category        | int(11)      | NO   |     | NULL                |                |
| team            | int(11)      | NO   |     | NULL                |                |
| technology      | int(11)      | NO   |     | NULL                |                |
| owner           | int(11)      | NO   |     | NULL                |                |
| manager         | int(11)      | NO   |     | NULL                |                |
| assessment      | longtext     | NO   |     | NULL                |                |
| notes           | longtext     | NO   |     | NULL                |                |
| submission_date | timestamp    | NO   |     | CURRENT_TIMESTAMP   |                |
| last_update     | timestamp    | NO   |     | 0000-00-00 00:00:00 |                |
| review_date     | timestamp    | NO   |     | 0000-00-00 00:00:00 |                |
| mitigation_id   | int(11)      | NO   |     | NULL                |                |
| mgmt_review     | int(11)      | NO   |     | NULL                |                |
| project_id      | int(11)      | NO   |     | 0                   |                |
| close_id        | int(11)      | NO   |     | NULL                |                |
| submitted_by    | int(11)      | NO   |     | 1                   |                |
| filename        | varchar(30)  | NO   |     | NULL                |                |
+-----------------+--------------+------+-----+---------------------+----------------+
21 rows in set (0.00 sec)

**mysql> INSERT INTO risks (`status`, `subject`, `reference_id`, `location`, `category`,
`team`, `technology`, `owner`, `manager`, `assessment`, `notes`,'filename')     VALUES 
('san', 'ss', 1, 1, 1, 1, 2, 1, 1, 'sment', 'notes','santu');**

ERROR 1064 (42000): 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 ''filename') 
VALUES ('san', 'ss', 1, 1, 1, 1, 2, 1, 1, 'sment', 'notes','sant' at line 1

13014
2018-02-25 09:18


起源



答案:


MySQL中有两种不同类型的引号。您需要使用`用于列名称和'用于字符串。由于您已使用'for filename列,因此查询解析器感到困惑。删除所有列名称周围的引号,或将“filename”更改为“filename”。然后它应该工作。


13
2018-02-25 09:31





不要引用列文件名

mysql> INSERT INTO risks (status, subject, reference_id, location, category, team,    technology, owner, manager, assessment, notes,filename) 
VALUES ('san', 'ss', 1, 1, 1, 1, 2, 1, 1, 'sment', 'notes','santu');

3
2018-02-25 09:20





C:\xampp>mysql -u root -p mydatabase < C:\DB_Backups\stage-new.sql
Enter password:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the ma
nual that corresponds to your MySQL server version for the right syntax to use n
ear 'stage-new.sql

----lot of space----

' at line 1

原因是当我使用以下命令转储数据库时:

mysqldump -h <host> -u <username> -p <database> > dumpfile.sql
dumpfile.sql

错误的dumpfile.sql在语法中添加了两次。

方案: 我删除了 dumpfile.sql 文本添加到导出的转储文件的第一行。


1
2018-05-04 12:01





这个错误是由于同一个表存在于2个数据库中,就像你有一个project1的数据库,并且你有表emp,你又有另一个数据库,比如project2,当你尝试在数据库中插入一些东西时,你有表emp没有你的数据库名称,你会得到一个类似的错误

使用mysql查询时的解决方案,然后还提到数据库名称和表名称。

要么

不要使用KEY之类的保留关键字作为列名


1
2017-07-29 06:13





嘿朋友们,

             Executing dump query in terminal then it will work

mysql -u root -p>


-3
2018-05-19 15:39