“Expected one of #, {, }... Elasticsearch整合Logstash发生的报错,statement报错

使用.\logstash.bat -f …\config\mysql.conf时发生如下报错…

logstash "Expected one of #, if, “, ', } at line37, column 1 (byte 9) after input {\n”,

这一行正是写sql语句的地方,于是博主对着这条sql陷入了沉思…
配置文件:
“Expected one of #, {, }... Elasticsearch整合Logstash发生的报错,statement报错
“Expected one of #, {, }... Elasticsearch整合Logstash发生的报错,statement报错
粘贴sql到navicat执行:
“Expected one of #, {, }... Elasticsearch整合Logstash发生的报错,statement报错
结果sql是正常的!!!!

解决方案:
离开工位,接一杯水冷静冷静…最后找出罪魁祸首:
“Expected one of #, {, }... Elasticsearch整合Logstash发生的报错,statement报错
mysql中查询语句中的单引号和双引号可用于引用"字符串"常量,两者使用起来没有区别。
但是在此处,如果使用双引号,则会让Logstash解析mysql.conf配置文件时 提前认为倒数第三个 " 是结束符 ,导致报错!

至此,问题解决。

写在最后:
mysql 里面有个 sql mode 叫做:ANSI_QUOTES 。这个 ANSI_QUOTES 开启后会把 双引号当作 ``。
所以我们还是建议使用单引号来引用字符串。

mysql 官方文档原文解释:

ANSI_QUOTES

Treat " as an identifier quote character (like the quote character) and not as a string quote character. You can still use to quote identifiers with this mode enabled. With ANSI_QUOTES enabled, you cannot use double quotation marks to quote literal strings because they are interpreted as identifiers.

参考文档:https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html