0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MQTTのMessageを残らずMySQL(MariaDB)に保存するコマンド

Last updated at Posted at 2019-10-20

#個人的なメモ

db構造


sudo mysql -e "SHOW FULL COLUMNS FROM mqtt.msg"
+-------+---------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
| Field | Type          | Collation         | Null | Key | Default | Extra | Privileges                      | Comment |
+-------+---------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
| m     | varchar(1124) | latin1_swedish_ci | YES  |     | NULL    |       | select,insert,update,references |         |
| tm    | int(11)       | NULL              | YES  |     | NULL    |       | select,insert,update,references |         |
+-------+---------------+-------------------+------+-----+---------+-------+---------------------------------+---------+

コマンド

mosquitto_sub -t "#" -v | xargs -I@ sudo mysql -e "insert into mqtt.msg (m,tm)values('@',$(date +%s))"

上記だと、時間が固定になってしまいます。
SQLの方で持ってくるように変更

mosquitto_sub -t "#" -v | xargs -I@ sudo mysql -e "insert into mqtt.msg (m,tm)values('@',UNIX_TIMESTAMP(NOW()))"

課題

・セキュリティ的に問題有り
・トピックとMessageが分割できていない

commentいただけると嬉しいです!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?