错误1064(42000):在SQL语法中有一个错误;检查与MySQL服务器版本对应的手册,以便使用正确的语法。

时间:2021-02-24 23:13:10

While I am trying to insert a row to my table, I'm getting the following errors:

当我试图向表中插入一行时,我得到了以下错误:

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

please help me out.

请帮帮我。

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

5 个解决方案

#1


12  

There are two different types of quotation marks in MySQL. You need to use ` for column names and ' for strings. Since you have used ' for the filename column the query parser got confused. Either remove the quotation marks around all column names, or change 'filename' to `filename`. Then it should work.

MySQL中有两种不同类型的引号。您需要使用“用于列名和”字符串。由于您已经使用了“对于文件名列”,查询解析器会感到困惑。要么删除所有列名周围的引号,要么将“文件名”改为“filename”。那么它应该工作。

#2


3  

Don't quote the column filename

不要引用列文件名。

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


1  

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

The reason was when I dumped the DB I used following command :

原因是当我丢弃DB时,我使用了以下命令:

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

By mistaken dumpfile.sql added twice in the syntax.

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

Solution : I removed the dumpfile.sql text added to first line of the exported dumpfile.

解决方案:我删除了dumpfile。添加到导出的dumpfile的第一行的sql文本。

#4


1  

This Error comes due to same table exist in 2 database like you have a database for project1 and in which you have table emp and again you have another database like project2 and in which you have table emp then when you try to insert something inside the database with-out your database name then you will get an error like about

这个错误是由于同一表中存在2数据库就像你有一个数据库project1而你又有表emp和另一个数据库project2和你表emp然后当你试图插入一些内部数据库型数据库名称然后你会得到一个错误

Solution for that when you use mysql query then also mention database name along with table name.

当您使用mysql查询时,也会提到数据库名称和表名。

OR

Don't Use Reserved key words like KEY as column name

不要使用关键字,如键作为列名。

#5


-2  

Hey Friends,

嘿,朋友,

             Executing dump query in terminal then it will work

mysql -u root -p >

u的平方根-p >。

#1


12  

There are two different types of quotation marks in MySQL. You need to use ` for column names and ' for strings. Since you have used ' for the filename column the query parser got confused. Either remove the quotation marks around all column names, or change 'filename' to `filename`. Then it should work.

MySQL中有两种不同类型的引号。您需要使用“用于列名和”字符串。由于您已经使用了“对于文件名列”,查询解析器会感到困惑。要么删除所有列名周围的引号,要么将“文件名”改为“filename”。那么它应该工作。

#2


3  

Don't quote the column filename

不要引用列文件名。

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


1  

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

The reason was when I dumped the DB I used following command :

原因是当我丢弃DB时,我使用了以下命令:

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

By mistaken dumpfile.sql added twice in the syntax.

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

Solution : I removed the dumpfile.sql text added to first line of the exported dumpfile.

解决方案:我删除了dumpfile。添加到导出的dumpfile的第一行的sql文本。

#4


1  

This Error comes due to same table exist in 2 database like you have a database for project1 and in which you have table emp and again you have another database like project2 and in which you have table emp then when you try to insert something inside the database with-out your database name then you will get an error like about

这个错误是由于同一表中存在2数据库就像你有一个数据库project1而你又有表emp和另一个数据库project2和你表emp然后当你试图插入一些内部数据库型数据库名称然后你会得到一个错误

Solution for that when you use mysql query then also mention database name along with table name.

当您使用mysql查询时,也会提到数据库名称和表名。

OR

Don't Use Reserved key words like KEY as column name

不要使用关键字,如键作为列名。

#5


-2  

Hey Friends,

嘿,朋友,

             Executing dump query in terminal then it will work

mysql -u root -p >

u的平方根-p >。