【发布时间】:2020-06-25 14:31:05
【问题描述】:
我有一个 mysql 查询来使用另一个表(index_tmp)中的列名更新一个表(索引)数据,这是查询
INSERT INTO index(
`CIN`, `companyName`, `Charge ID`, `Date of Charge`,
`Charge amount secured`, `Charg Holder`, `Address`,
`SRN`, `Created_Date`, `Modified_Date`,
`Date_Of_Satisfaction`, `Change`)
SELECT `CIN`, `companyName`, `Charge ID`, `Date of Charge`,
`Charge amount secured`, `Charge Holder`, `Address`,
`SRN`, `Created_Date`, `Modified_Date`,
`Date_Of_Satisfaction`, `Change`
FROM index_tmp where `Change` = "New"
这个查询在 mysql 中运行没有任何错误,但是当我尝试从命令行运行它时,我得到以下错误,
$ mysql -uroot -p -e "query"
bash: CIN: command not found
bash: companyName: command not found
bash: Charge: command not found
bash: Date: command not found
bash: Charge: command not found
bash: Charge: command not found
bash: Address: command not found
bash: SRN: command not found
bash: Created_Date: command not found
bash: Modified_Date: command not found
bash: Date_Of_Satisfaction: command not found
bash: Change: command not found
bash: CIN: command not found
bash: companyName: command not found
bash: Charge: command not found
bash: Date: command not found
bash: Charge: command not found
bash: Charge: command not found
bash: Address: command not found
bash: SRN: command not found
bash: Created_Date: command not found
bash: Modified_Date: command not found
bash: Date_Of_Satisfaction: command not found
bash: Change: command not found
bash: Change: command not found
ERROR 1064 (42000) at line 1: 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 ',,,,,,,,,,) SELECT ,,,,,,,,,,, FROM index_of_charges_tmpd where = New' at line 1
Mysql 5.6 版
【问题讨论】:
-
索引是mysql中的保留字,如果在mysql中运行成功,你一定是反引号了。
-
表全名为index_charge。我正在尝试在 CLI 中运行它,例如 mysql -uroot -p -e "full_query" 并收到错误。
-
@sam 使用单引号而不是双引号,否则 shell 会将反引号作为命令插入。
-
请使用tour 并阅读How to Ask。特别是,您的问题不包括minimal reproducible example,因此是题外话。另外,请查看您应用的标签的描述,其中一半是错误的。
-
在 bash 中,反引号表示要执行它们之间的文本。所以它试图运行命令 CIN, companyName, ... 要在命令行中运行查询,你应该做一些研究,这已经在 SO 上多次解决了。