ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以了解要使用的正确语法

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22009582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:06:55  来源:igfitidea点击:

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

mysql

提问by santu47

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

回答by Ohlin

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 中有两种不同类型的引号。您需要将 ` 用于列名, ' 用于字符串。由于您已将 ' 用于文件名列,因此查询解析器感到困惑。删除所有列名周围的引号,或将“文件名”更改为“文件名”。那么它应该工作。

回答by Deepak

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

回答by Boolment Software

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

不要使用像 KEY 这样的保留关键字作为列名

回答by Mukesh

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 :

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

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.sqltext added to first line of the exported dumpfile.

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

回答by Ajay Sharma

This solution is for windows:

此解决方案适用于 Windows:

  1. Open command prompt in Administrator Mode.
  2. Goto path: C:\Program Files\MySQL\MySQL Server 5.6\bin
  3. Run below command: mysqldump -h 127.0.01 -u root -proot db table1 table2 > result.sql
  1. 在管理员模式下打开命令提示符。
  2. 转到路径:C:\Program Files\MySQL\MySQL Server 5.6\bin
  3. 运行以下命令:mysqldump -h 127.0.01 -u root -proot db table1 table2 > result.sql

回答by Steven

I encountered this same error: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 ', completed)' at line 1

我遇到了同样的错误:ERROR 1064 (42000): You have an error in your SQL syntax; 检查与您的 MySQL 服务器版本相对应的手册,以了解在第 1 行的“,已完成)”附近使用的正确语法

This was the input I had entered on terminal:mysql> create table todos (description, completed);

这是我在终端上输入的输入:mysql> create table todos (description, completed);

Solution:For each column type you must specify the type of content they will contain. This could either be text, integer, variable, boolean there are many different types of data.

解决方案:对于每个列类型,您必须指定它们将包含的内容类型。这可以是文本、整数、变量、布尔值,有许多不同类型的数据。

mysql> create table todos (description text, completed boolean);

mysql> 创建表 todos(描述文本,完成的布尔值);

Query OK, 0 rows affected (0.02 sec)

查询正常,0 行受影响(0.02 秒)

It now passed successfully.

现在顺利通过了。

回答by Anshul Sharma

This error comes when you have a column name from one of the mysql keyword, try to run your queries by putting all your column names in `` this

当您有来自 mysql 关键字之一的列名时,会出现此错误,尝试通过将所有列名放在 `` this 中来运行查询

example: insert into test (`sno`, `order`, `category`, `samp`, `pamp`, `method`) values(1, 1, 'top', 30, 25, 'Total');

例如:插入测试(`sno`、`order`、`category`、`samp`、`pamp`、`method`) values(1, 1, 'top', 30, 25, 'Total');

In this example column name order is a keyword in mysql, so i had to put that in `` quotes.

在这个例子中,列名顺序是 mysql 中的一个关键字,所以我不得不把它放在 `` 引号中。

回答by Manikyam

Execute dump query in terminal then it will work

在终端中执行转储查询然后它会工作

mysql -u root -p  <Database_Name> > <path of the input file>