apk add pv
or sudo apt install pv
or something else depending on your system
i found a new way that works great now and did not even mess up my cost device @fversteegen
You right they did do something so this is what i did after the old method did not work anymore.
What do you need:
Heidi sql (sql manager)
MariaDB or proxmox LXC Tteck scripts (AWSOME GUY!!!)
Home Assistant
Adminer (its ike phpmyadmin) i prefer this
or
Phpmyadmin
The set-up:
- ssh into homeassistant and duplicated the .DB called homeassistant_v2.db.
- Created a new database with HEIDI with
Just open HEIDI and login to your mysql and create the DB
utf8mb4_general_ci and name homeassistant this is the database we gonna use later, now let homeassistant
Now we need to change something in the homeassistant.yaml
To do that just go into your homeassistant.yaml and be sure the line of recorder looks like this, ofcourse donât forget to replace the ip username and password.
recorder:
db_url: mysql://USERNAME:PASSWORD@YOURIP/homeassistant?charset=utf8mb4
After you done this, save and restart homeassistant and let it run for 5 minutes and shut it down.
or if you dont want to shut it down just change the recorder back that it uses the old default database file again.
-
open heidi and select the database named homeassistant and empty all rows/tables and delete all keys from all tables (not the orange ones!) using (heidi sql)
just hover over the key and press remove
-
created a new database called (homeassistant_test) the old dump database
-
now we start using the script again to dump the same homeassistant.db we backed up before again into the new created database. homeassistant_test) c6de-
sqlite3mysql
âsqlite-file /config/home-assistant_v2.db
âmysql-database homeassistant
âmysql-host core-mariadb
âmysql-user homeassistant_test
âmysql-password âYOURPASSWORDâ
âignore-duplicate-keys
-
go to homeassistant_test database and check the data of homeassistant_test and look for the table statistics_short_term and open it, copy the (CREATED) row (im using heidi sql)
-
than open statistics_short_term in the database named homeassistant and paste the row
it does not matter where
-
compare the rows from homeassistant_test with homeassistant and
be sure in (events | recorder_runs | states,statistics )have the colum (created) if not just copy them over, (use the corresponding column from the other database) -
also check if there are missing columns in homeassistant u can copy them to from homeassistant_test
-
now finally we run the script again and once more we use the homeassistant.db we created in the beginning and this time we gonna dump it in the database named homeassistant thats the one we edited and made it ready and compatible with mariadb.
sqlite3mysql
âsqlite-file /config/home-assistant_v2.db
âmysql-database homeassistant
âmysql-host core-mariadb
âmysql-user homeassistant
âmysql-password âYOURPASSWORDâ
âignore-duplicate-keys
if everything went ok and you open the DB u see that FLOAT changed to DOUBLE
see here my old homeassistant_test
new dumped homeassistant
Go in to the homeassistant YAML file and add it to the recorder and start HASS and BOOM it works.
I did a mix of everyone but none of that data went corrupted or lost during this migration, atleast not for me.
Also a big plus is that the COST entity wonât get messed up at all
So whoever wants to try this always make a BACKUP!
Thanks to @eddiewebb @spitf1r3 @SirACEair @Alex_Pupkin for theyr info and scripts so i could make a tutorial.
I tested this on my local server and proxmox HASS server, working great.
My Mariadb LXC is installed on Proxmox
Tteck scripts (AWSOME GUY!!!)
An update, well still working without an issue, and the migration went fine on all 3 systems.
1 had over 5gb of data, even the cost device did not mess up.
// 17-03-2023 Still working without an error or data problems.
Qabout1: Whatâs a HSD?
Qabout2: How to create a database manually?
Qabout3: you ment the red ones when writing orange?
Qabout4: donât get it whats a dump_database
I appreciate your work on that for a while and always tried to get the sense of it and it partly worked apart from the energy/price destaster but this time you completely lost me. Itâs sort of workflow designed for graduated database engineers only I assume.
Will there be a âfor the dumb dudesâ version some day?
Qabout1: Whatâs a HSD?
sorry thats indeed a typo, it must be homeassistant.db
Qabout2: How to create a database manually?
i updated the tutorial
Qabout3: you ment the red ones when writing orange?
i updated the tutorial, it clearly shows all keys what need to be deleted but in the screenshot the red key was selected.
Qabout4: donât get it whats a dump_database
thats the name i used for the tutorial database name, i updated the tutorial and change the name and made clear what is it.
if i have time i maybe can make a step by step video, but its a lot of work.
Everything fine, wonât need a video at all. And yes summing up my luckless attempts to get things migrated wasnât work at all, but eating up time like hell.
And since your hints from the past days/weeks did bring me most closest to the finishing line it was a bit strange since I got stuck at the starting grid (point 1)
Thanks a lot for you effort in making it more readable/understandable.
Thanks for that super howto, one question regarding step 8 & 9:
In some tables there arenât the âcreatedâ row. so, it is important that all tables have a created row or it is important that the columns are equal?
In my case, there is no âcreatedâ row in the events table homeassistant_test:
therefore I donât create one in the homeassistant db, right?
EDIT: it works without the created row, so I assume, that only the rows between the 2 db have to be equal.
Thanks for your Guide, that was the only one which helped in my case
Sorry for the late reply.
Iâm glad i could help, for me everything still working on 3 servers.
About the CREATED row is only needed to be inserted if its missing in the new created database.
Just compare the old and new and its ok, it doesnât have to be in every table
I recommand all people who have very less knowledge about the migration to MARIADB, just donât do it!.
See what the developers have to say at the 2023.4 release party.
Here is the video at the correct timestamp
I have captured the above information regarding the recommendations to not use mysql / mariadb unless you KNOW what you are doing as a database administrator to the beginning post for this topic.
anybody moved back to sqlite after 2023.4 improvements?
wondering the same if anyone switched back to SQLite.
Is it worth it if we have a good working setup with mariadb right now?
I donât need external access to the database⌠I just want the best performance.
Yes I switched back and succeeded. If itâs worth, is up to you.
The HA developers recommend using SQLite as the DB and made some really spectacular improvements on the performance.
See my âmanualâ (no guarantee):
I switched back to SQlite as well:
- Finished - I was in the process of migrating during the announcement of 2023.4 - the migration to MariaDB.
- Created a full backup of HA with the new migrated MariaDB.
- Restored a previous day old full back up with SQlite 2023.3
- Updated to the announced HA 2023.4 with SQLite Turbo
- Still working with the updated SQLite, sailing very smooth.
I my experience the new 2023.4 SQLite is working really great, very snappy and light weighted. I realize this is not a scientifically approach to comparing DBâs.
All together a great revert. Moving onâŚ
Great update HA Team.
Hello,
are there any news or update about this topic ?
I tried to migrate (SQLite â MariaDB) following these notes but with core 2023.5 it seems that doesnât work.
Iâm going crazy because it would be very useful for me to have one steady database shared between a couple of homeassistant nodes (a sort of cluster, letâs say, only one node working at time, the second node only for redundancy/manteinance).
Thank you so much, appreciate the help!
Had to delete the database and igoner duplicate keys to get my energy data to transfer
Iâm having issues on converting to Mariadb. I have an empty database âhomeassisantâ.
When I try to run sqlite3mysql:
Command:
sqlite3mysql --sqlite-file /config/home-assistant_v2.db --mysql-database homeassistant --mysql-host 192.168.1.x --mysql-user peter --mysql-password 'SECRET' --debug
Response:
Traceback (most recent call last):
File â/usr/bin/sqlite3mysqlâ, line 8, in
sys.exit(cli())
File â/usr/lib/python3.10/site-packages/click/core.pyâ, line 1130, in call
return self.main(*args, **kwargs)
File â/usr/lib/python3.10/site-packages/click/core.pyâ, line 1055, in main
rv = self.invoke(ctx)
File â/usr/lib/python3.10/site-packages/click/core.pyâ, line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File â/usr/lib/python3.10/site-packages/click/core.pyâ, line 760, in invoke
return __callback(*args, **kwargs)
File â/usr/lib/python3.10/site-packages/sqlite3_to_mysql/cli.pyâ, line 204, in cli
converter.transfer()
File â/usr/lib/python3.10/site-packages/sqlite3_to_mysql/transporter.pyâ, line 736, in transfer
self._create_table(table[ânameâ], transfer_rowid=transfer_rowid)
File â/usr/lib/python3.10/site-packages/sqlite3_to_mysql/transporter.pyâ, line 360, in _create_table
column_type = self._translate_type_from_sqlite_to_mysql(column[âtypeâ])
File â/usr/lib/python3.10/site-packages/sqlite3_to_mysql/transporter.pyâ, line 287, in _translate_type_from_sqlite_to_mysql
raise ValueError(âInvalid column_type!â)
ValueError: Invalid column_type!
The connection is being made successfully, as Iâve deleted the homassistant database manually and it recreated it with sqlite3mysql.
Any idea on how to fight this?
I just want to add that I used dbeaver to migrate data without any problem (homeassistant in docker, mariadb installed locally):
- create empty mariadb database
- stop home-assistant
- configure home-assistant to use mariadb
- run home-assistant and stop it to create empty tables on mariadb
- truncate mariadb tables (could be done at migration time)
- configure on dbeaver both sqlite database and mariadb, and use it to migrate data
Some data types may be different in MariaDB than in SQLite (and it may cause corruption of some states/other data), have you checked this?
I havenât done rigorous check, just checked if âupdatesâ from firsts posts were necessary and they werenât.