
Put the Home Assistant DB in MariaDB
Call me meticulous, but I usually put the Home Assistant database on an external server with MariaDB or MySQL, since I usually make remote queries to the DB with some system, or for the issue of backup, robustness, etc… It is not something usual to do, But I'll leave you the steps in case you need it!
What I said, if by chance we are interested in storing all the information from Hassio or Home Assistant on a MariaDB database server, we must follow these simple steps. Assuming that we already have a MariaDB or MySQL server installed and functional.
From the Home Assistant or Hassio web console, we'll add the MariaDB add-on, from the menu “Hass.io” > “Add-On Store”. There we will have a multitude of interesting components that we can add to Hassio to integrate it with more systems or give it more functionality. In this case we look for the MariaDB AddOn and click on “Install”.
Now we will connect to our MariaDB server, We will create the database 'Hassio’ and we'll create a user called 'homeassistant'’ with the password we are interested in. Later we will give the user privileges over the database that we have just created, with:
[SourceCode]mysql -u root -p
Create Database hassio;
CREATE USER 'homeassistant'@'%’ IDENTIFIED BY 'PASSWORD';
GRANT ALL ON hassio.* TO 'homeassistant'@'%';
Quit[/SourceCode]
In our Hassio or Home Assistant configuration file we must point to said server and said database, We edit 'configuration.yaml’ and at the end we added:
[SourceCode]recorder:
db_url: Mysql://HomeAssistant:CONTRASEÑA@DIRECCION_IP_MARIA_DB/hassio?charset=utf8
purge_keep_days: 365
exclude:
entities:
– sun.sun[/SourceCode]
As we can see, I am also excluding some entity (Like the sun) so that you do not store your data for me, with this example we see how to exclude certain data that is stored in the DB. To reload the data as always, we must restart Hassio, we can do it as always by the GUI, or if we are in its shell and use Home Assistant in a container, it would be enough for us to:
[SourceCode]Docker Restart HomeAssistant[/SourceCode]
And after that we would already have the database moved and on our MariaDB server! Personally I rest better, this type of database I work better, apart from the issue of backups or when it comes to recovery if necessary, etc… And basically it's because at Centreon I usually make inquiries to BD, since Hassio goes quite far, but maybe with Centreon you add some control or additional information such as SLAs, Reports…