First you will need to create a DB and user account, this can be done by running the following commands while connected to mysql - make sure that you replace the relevant values with your own.
1 2 3 CREATE DATABASE `HomeAssistant2021`; CREATE USER 'hass' IDENTIFIED BY 'xxx'; GRANT ALL privileges ON `HomeAssistant2021`.* TO 'hass'@'%';
You can connect to mysql using the following command mysql -u root -p You should now have a DB called HomeAssistant2021 that can be accessed using the account you created.
It is generally a good idea to create periodic backups of your databases and should be done for your Home Assistant DB too. This post covers how to backup your DB via a CRON job.
Although this step is not required, it will make things a lot easier going forward. Under the Addon section in Home Assistant find and install the Studio Code Server addon.
First we will need to generate a connection string for your DB, referring to the official documentation I ended up with the following connection string.
I would suggest storing the connection string in your
I suggest creating a new file called
recorder.yaml in the root of your configuration folder and add the following content to it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 db_url: !secret recorder_db_url purge_keep_days: 7 commit_interval: 0 exclude: domains: - automation - updater entities: - sun.sun entity_globs: - sensor.*_last_update_trigger - sensor.*_last_notification - sensor.*_last_removed_notification - sensor.*_volume_level_music - sensor.*_volume_level_call
I am excluding certain domains and entities from being recorded
You can then add a reference to your configuration in configuration.yaml like so: recorder:
After making your changes you will need to validate your configuration and restart Home Assistant.
To restart Home Assistant press c on your keyboard and search for Restart Server in the context menu that appears.
Before restarting Home Assistant should validate your configuration and warn if there are any issues.
Before continuing I would suggest connecting to MariaDB and confirming that Home Assistant is writing changes to the DB, this is as simple as checking to see if the DB has grown in size and for the presence of new tables.
Once you have confirmed that Home Assistant is writing content to your DB you can go ahead and remove the old
home_assistant_v2.db file to free up some space on your server.