I took a simpler or lazier approach, and used a well supported library to quickly migrate home assistants sqlite database into MariaDB/MySQL with full history. There is no need to even transfer files - just a couple commands and done!
Prerequisites
install and activate MariaDB addon
Install and activate the Terminal & SSH addon
Maria DB Migration Steps
Stop the recorder service from developer tools
( âDeveloper Toolsâ > âServicesâ > Search for Recorder: Disable > Press the âCall serviceâ )
Start the Terminal & SSH addon (mariadb should be running as well)
Run the commands below to install python (already exists on host, super fast)
Run DB migration
Post-Migration (activation)
Configure HA to use new mariadb as recorder in configuration.yaml
will it work with HAOS?
Yes. The installed tools only need to exist as long as the commands take, and the Terminal & SSH add-on works great.
I got an error from mysql (invalid column, duplicate key, etc) !
Backup mysql, purge all tables, and try again. MariaDB tables should not exist when we start migratration, will be fiully created from sqlite. ONly the database itself should exist.
Can I use if database is on another host?
Yes, just change the â-hâ (hostname) argument to wherever it lives
Can I use with phpmysqladmin?
The python tool wants direct access to the MySQL database, just like phpmysql. You need access to the HA instance with ability to run python (hence Terminal addon)
What about Energy Dashboard (and statistics generally)?
Yep, all there. This migration should be everything in sqlite. (thanks @jusii, @malosaa)
My Energy costs are all messed up after migrating!
Giving Home Assistant a day to work through should correct this, (thanks @malosaa)
Are there size limits?
In theory any existing sqlite db can be migrated. only the resources of your machine limit that, but even little NUCs should get it done eventually.
And alsoâŠ
Tremendous thanks to all the folks below who tested, questioned, and refined this method! We got a winner!
So on which setup did you / can one use this? Will it work on HAOS too (because installing stuff is - if at all - only temporary due to the dockerization which is reset on container recreation etc.)?
I dont understand why you are concerned with the Phpmysql GUI though, the python script eliminates any need to interact with MySQL/MariaDB, it does all the commands directly to the database, whereever it may live.
Just did a quick test with this method and it actually looks pretty promising, even with the energy dashboard data! I have kinda spare HA-installation which only collects total energy stats and tested with that. All energy dashboard history looks to be there!
Not sure bout that, I think topics can be marked as sticky by the mods. But you could ask @jr3us to link your how-to in the original/first post so people donât need to waste much time reading 130 posts to find your guide
We now have I think two to three really good approaches here, while I personally think your how-to is the âbestâ in terms of easiest one (and when energy dashboard / LTS is working thatâs also a big pro versus few other guides which seem to struggle with that).
If someone can give me a block from the first step to the last that I can just paste into my original post as a text block similar to what I did originally, I will add it as the current favored method for migrating with credit to the user. I will leave the original for historic purposes.
I do see mentioned that a new instance of home assistant is in the steps involved. I donât think this will necessarily work for an already established HA instance with lots of data.
my steps to migrate sqlite to mariadb posted above works for established instances. mine has been running for 18 months, the process has no size limit. It will work for an HA instance with N data, where N is any amount possible by sqlite and resources available on device.