【问题标题】: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 useERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册以获取正确的语法使用
【发布时间】:2014-03-27 09:41:16
【问题描述】:

当我尝试向表中插入一行时,我收到以下错误:

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

【问题讨论】:

    标签: mysql


    【解决方案1】:

    我在 bash 脚本中编写代码

    name=$(cat $file | jq -r ".["$i"].name")    
    program_url=$(cat $file | jq -r ".["$i"].program_url")  
    url=$(cat $file | jq -r ".["$i"].url")      
    platform=$(cat $file | jq -r ".["$i"].platform")    
    bounty=$(cat $file | jq -r ".["$i"].bounty")
    sudo mysql  -u root -p "--password=4310260985" "programs"  -e "use programs;insert into website(name, program_url, url, platform, bounty) VALUES ('$name', '$program_url', '$url', '$platform', $bounty);"
    

    说明: 变量放入 (') 但 $bounty 未放入 (') 因为变量 $bounty 是 type=boolean

    【讨论】:

      【解决方案2】:

      将下面的代码保存为 command.sql

      USE restaurant
      TRUNCATE `orders`;
      TRUNCATE `order_items`;
      

      然后运行

      mysql -u root <comands.sql> output.tab
      

      【讨论】:

        【解决方案3】:

        ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 ' 附近使用的正确语法

        非常简单的问题,你可以轻松解决,

        请按照我的步骤:将 ; 更改为 );

        只需使用:(

             );
        

        在此处输入代码

        ` CREATE TABLE information (
        -> id INT(11) NOT NULL AUTO_INCREMENT,
        -> name VARCHAR(30) NOT NULL,
        -> age INT(10) NOT NULL,
        -> salary INT(100) NOT NULL,
        -> address VARCHAR(100) NOT NULL,
        -> PRIMARY KEY(id)
        -> );`
        

        【讨论】:

        • 如果你只是设计它,也许答案会变得更好。我的意思是你可以删除一个enter code 部分。有一个);
        • 这是解决此问题的更好方法,因为这是更新的结果!如果你写 >;它比你会面临一个问题但是如果你写这个);它会成功的!
        【解决方案4】:

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

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

        在这个例子中,列名 order 是 mysql 中的一个关键字,所以我必须把它放在``引号中。

        【讨论】:

        • 一般我们在命名表格中的列时不会记住关键字,所以最好将所有列放在 `` 引号中。
        【解决方案5】:

        在终端执行转储查询就可以了

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

        【讨论】:

        • 为我修好了。实际有用的信息
        【解决方案6】:

        我遇到了同样的错误: ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的 ', completed)' 附近使用正确的语法

        这是我在终端输入的内容: mysql> 创建表 todos(描述,完成);

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

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

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

        现在顺利通过了。

        【讨论】:

          【解决方案7】:

          此解决方案适用于 windows:

          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

          【讨论】:

            【解决方案8】:

            此错误是由于 2 个数据库中存在同一个表,例如您有一个用于 project1 的数据库,并且您在其中有表 emp,并且您有另一个数据库,如 project2,并且您在其中有表 emp,然后当您尝试插入某些内容时在没有你的数据库名称的数据库中,你会得到一个类似的错误

            解决方案,当你使用 mysql 查询时,还要提到数据库名和表名。

            不要使用保留关键字如 KEY 作为列名

            【讨论】:

              【解决方案9】:
              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 文本。

              【讨论】:

                【解决方案10】:

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

                【讨论】:

                  【解决方案11】:

                  不要引用列文件名

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

                  【讨论】:

                    猜你喜欢
                    • 2018-04-04
                    • 2017-09-12
                    • 2017-11-22
                    • 2021-12-03
                    • 2019-11-22
                    • 2018-11-09
                    • 2015-10-23
                    • 2017-06-01
                    相关资源
                    最近更新 更多