[How to] Query MariaDB directly without Python or Shell
I have been trying to write directly to MariaDB or read something from it since 8 am.
ALL forum entries so far have said that this is not possible because it is executed in isolation. Phyton and or shell scripts were always the solution.
I disagree with that now.
/homeassistant/configuration.yaml
shell_command:
execute_sql: “/usr/bin/mariadb --ssl=0 -h core-mariadb -u homeassistant -phomeassistant -D homeassistant -e \”SELECT * FROM `statistics_runs` LIMIT 10;\” >> /config/sql_debug.log 2>&1”
/homeassistant/automations.yaml
- alias: “Execute SQL query”
trigger:
- platform: time
at: “23:59:50”
action:
- service: shell_command.execute_sql
Maybe this will help someone at some point. It has now cost me half the day
homeassistant as password must still be adjusted by you (if necessary).
The command can be executed directly for testing. It is only a SELECT statement.
The output is saved in sql_debug.log.
So /homeassistant/sql_debug.log
The logging can be updated (already in there)
>> /config/sql_debug.log
If you always want to have a fresh log, then remove a >
> /config/sql_debug.log
The rest should take care of itself