【问题标题】:Cant get a response from MySQL using NodeRed function使用 Node Red 函数无法从 MySQL 获得响应
【发布时间】:2021-04-05 03:28:41
【问题描述】:

我想从 NodeRed mysql 节点中退出。我想向 MySQL 发送一个查询并接收一个输出,该输出给出了我的数据库的大小。数据库名称为 demoopcua。

这是连接的图像:

这是我的功能:

msg.topic = "SELECT table_schema AS demoopcua,ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS `Size (MB)`,FROM information_schema.TABLES GROUP BY table_schema;"

如果你想导入它,这里是流程:

[{"id":"a98232e2.89bb4","type":"tab","label":"Data Storage ","disabled":false,"info":""},{"id":"f50611a.320baf","type":"mysql","z":"a98232e2.89bb4","mydb":"f1e0508e.13503","name":"db","x":470,"y":360,"wires":[["73e15eff.866b3"]]},{"id":"73e15eff.866b3","type":"debug","z":"a98232e2.89bb4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":360,"wires":[]},{"id":"6936d2d6.33b00c","type":"function","z":"a98232e2.89bb4","name":"","func":"msg.topic = \"SELECT table_schema AS demoopcua,ROUND(SUM(data_length + index_length) / 1024 / 1024, 2) AS `Size (MB)`,FROM information_schema.TABLES GROUP BY table_schema;\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":360,"wires":[["f50611a.320baf"]]},{"id":"ee29a71.86c0b58","type":"inject","z":"a98232e2.89bb4","name":"","props":[{"p":"payload"},{"p":"topic","v":"","vt":"msg"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":360,"wires":[["6936d2d6.33b00c"]]},{"id":"f1e0508e.13503","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"test dump","tz":"","charset":"UTF8"}]

【问题讨论】:

  • 如果没有数据库架构,我们将无能为力。此外,这很可能是 SQL 问题而不是 Node-RED 问题,假设您在提交该查询时没有收到任何错误。
  • 我不太清楚你所说的数据库模式是什么意思。此外,当我运行此流程时,我确实收到了错误消息。我明白了:"Error: Invalid property expression: zero-length"
  • 检查 SQL 查询中的单引号,它们可能应该是 ' 而不是 `
  • 我仍然得到同样的零长度错误:(。我为任何误解道歉。我对此很陌生,我仍在学习。
  • 数据库架构为表布局en.wikipedia.org/wiki/Database_schema

标签: mysql sql database node-red


【解决方案1】:

问题出在您的注入节点上。您已将主题配置为从不存在的(空)msg 变量中设置。

单击msg.topic 行末尾的叉号删除此条目。

【讨论】:

  • 这里重要的一点是,您将鼠标放在错误上会显示它来自哪个节点
  • 解决了零长度错误:D 但它给了我另一个错误"Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'FROM information_schema.TABLES GROUP BY table_schema' at line 1"
【解决方案2】:

所以我终于找到了解决这个问题的方法。要解决此问题,请放置一个注入节点并将此 MySQL 查询复制到 msg.topic 中。

SELECT table_schema "your database name here", sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB" FROM information_schema.TABLES GROUP BY table_schema ;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 2020-08-25
    • 2021-07-18
    • 2018-02-20
    • 2020-12-11
    • 1970-01-01
    相关资源
    最近更新 更多