{"id":414,"date":"2021-07-04T19:24:37","date_gmt":"2021-07-04T19:24:37","guid":{"rendered":"https:\/\/andrejacobs.org\/?p=414"},"modified":"2022-04-11T20:22:59","modified_gmt":"2022-04-11T20:22:59","slug":"convert-home-assistant-to-use-mariadb-as-the-database","status":"publish","type":"post","link":"https:\/\/andrejacobs.org\/home-automation\/convert-home-assistant-to-use-mariadb-as-the-database\/","title":{"rendered":"Convert Home Assistant to use MariaDB as the database"},"content":{"rendered":"\n
Photo by Markus Winkler<\/a> on Unsplash<\/a><\/p>\n\n\n\n Currently my Home Assistant is using the default SQLite database for recording sensor data but I would like to use MariaDB instead. This is part of my Day 14 of 100 Days of STEM<\/a>.<\/p>\n NOTE:<\/strong> My Home Assistant setup is running on a Raspberry Pi 3 using a SSD drive, so using MariaDB will be fine in my case.<\/p>\n VERY IMPORTANT: You will lose all the previous recorded sensor data if you switch databases.<\/strong><\/p>\n My overall objectives to achieve over the next couple of days are:<\/p>\n By default Home Assistant uses a SQLite database for storing the recorded sensor data. The database is located at <\/p>\n <\/p>\n <\/p>\n <\/p>\n My Home Assistant is now using MariaDB for storing all the sensor data and the next task would be to setup remote backing up to Amazon S3 and my local Linux server.<\/p>\nOverview<\/h2>\n
Objectives<\/h2>\n
\n
\/config\/home-assistant_v2.db<\/code><\/p>\n
Initial steps<\/h2>\n
\n
homeassistant.tar.gz<\/code> file. The database file is named
home-assistant_v2.db<\/code>.<\/li>\n
\n
Observer<\/code> that can give clues as to what is happening on Home Assistant. The port is
4357<\/code>. Local link<\/a>.\nThe UI doesn’t always indicate what is going on behind the scenes and it is worth always waiting and doing a page refresh. Go grab that tea.<\/li>\n<\/ul>\n
\n
Setting up MariaDB<\/h2>\n
\n
Configure Home Assistant to use MariaDB for recording<\/h2>\n
\n
recorder<\/code> module.<\/li>\n
\/config\/configuration.yaml<\/code>. For this I am using the File editor add-on, but you can also use SSH.<\/li>\n<\/ul>\n
# Change the username,password and database name as required\nrecorder:\n db_url: mysql:\/\/homeassistant:password@core-mariadb\/homeassistant?charset=utf8mb4\n<\/code><\/pre>\n
\n
\n
Accessing MariaDB remotely<\/h3>\n
\n
databases:\n - homeassistant\nlogins:\n - username: homeassistant\n password: <<generated>>\n - username: ha-readonly\n password: <<generated>>\nrights:\n - username: homeassistant\n database: homeassistant\n - username: ha-readonly\n database: homeassistant\n privileges:\n - SELECT\n<\/code><\/pre>\n
\n
\n
Wrapping up for today<\/h2>\n
References<\/h2>\n