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

#個人的なメモ

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いただけると嬉しいです!