How to convert Home Assistant database to MariaDB



This video is a tutorial on how to convert the default Home Assistant database to MariaDB.

Here are a few links to get you started…..

As always, make sure your system is up to date…

sudo apt-get update
sudo apt-get upgrade

Lets start installing everything…..

sudo apt-get install software-properties-common

sudo apt-key adv –recv-keys –keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8

sudo add-apt-repository ‘deb [arch=amd64,i386,ppc64el] xenial main’

Now lets run update again and then install MariaDB…

sudo apt-get update
sudo apt-get install mariadb-server

It will prompt you for a default admin password to use with MariaDB

Once thats done, lets install a few more pieces needed for this to work with HA….

sudo apt-get install libmariadb-client-lgpl-dev libssl-dev
pip3 install mysqlclient

In order to convert the existing db over we need to install sqlite3

sudo apt-get install sqlite3

Now we are ready to stop Home Assistant to start working with the db…
sudo systemctl stop home-assistant.service

First we need to do a dump of the db……

sqlite3 home-assistant_v2.db .dump (ANGLE BRACKET) sqlite3_dbfile_.dump.sql

Now we need to download the sqlite to mysql converter….

git clone
cd sqlite3-to-mysql/
sudo ./sqlite3-to-mysql ../sqlite3_dbfile_.dump.sql (ANGLE BRACKET) ../mysql_importme.sql

Now we are ready to create the db in Mariadb…

mysql -u -root -p
create database homeassistant;

grant all privileges on homeassistant.* to ‘hass’ identified by ‘PASSWORD’
exit

Now we are ready to import the converted db into our newly created db…..

mysql -u hass -p -h localhost homeassistant (ANGLE BRACKET) mysql_importme.sql

Once that is done importing, we need to make a few tweaks….

mysql -u hass -p
use homeassistant
select max(run_id) from recorder_runs;
(IT SHOULD RETURN A NUMBER)

alter table recorder_runs modify column run_id INT NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=106;(NUMBER RETURNED PREVIOUSLY **INCREASED BY 1)

alter table states drop foreign key states_ibfk_1;

select max(event_id) from events;
(IT SHOULD RETURN A NUMBER)

alter table events modify column event_id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=183522; (NUMBER RETURNED PREVIOUSLY **INCREASED BY 1)

Now we can update configuration.yaml file…..

recorder:
db_url: mysql://hass:PASSWORD@localhost/homeassistant

Now that all the changes have been made, start HA back up….

sudo systemctl start home-assistant.service

That should be it, you should now be up and running on the mariadb database.

If you like the video, please subscribe to my channel. If you have any questions, hit me up in the comments below. Also, if there are any videos you would like me to put out here, let me know as well.

Nguồn:https://hdwallpaperslovely.com/

Related Posts

ADATA SU750 SSD Unboxing, Installation, Cloning, and Bench marking

February 1, 2020

February 1, 2020 4

I unbox my brand-new ADATA SU750 1TB SSD and install it in an old, slow desktop PC in an attempt...

How to install Adobe Photoshop CS6 Portable Camera Raw on Windows System | TakeIT

May 5, 2020

May 5, 2020 12

Hello..! In this video tutorial you will learn how to download and install Adobe Photoshop CS6 Portable (Camera Raw)_32Bit version...

How to install adb driver Manually on Windows 10 x64 bit

February 22, 2020

February 22, 2020 1

Hello friends… aaj hum dekhenge k kaise windows 10 64bit mein adb driver manually install karte ha. koi v mobile...

Check out what you can create with Adobe Animate CC 2020 the premiere animation tool from Adobe!

May 3, 2020

May 3, 2020 8

Adobe Animate CC animation software updates! It’s a complete privilege to get to work with the Adobe Animate engineering team...

Solved "You need permission to perform this action" Windows 7

March 5, 2020

March 5, 2020 29

UAC (User Account Control) does not usually affect this problem, so don’t go out and disable UAC. For this to...

Hướng dẫn học Adobe flash căn bản – Bài 1- Motion tween

March 25, 2020

March 25, 2020 13

Hướng dẫn học Adobe flash căn bản – Bài 1- Motion tween Adobe Flash hay còn gọi một cách đơn...

ADB Mi Account Anti Relock

February 1, 2020

February 1, 2020 5

ADB Mi Account Anti Relock ADB Mi Account Anti Relock ADB Mi Account Anti Relock Unduh : Password : adanichell...

"Device not found" RESOLVIDO! | TUTORIAL | MOTO E, G, E MAXX

April 2, 2020

April 2, 2020 27

▬▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬▬▬▬▬ ▓▓▓▒▒▒░░░ LEIA A DESCRIÇÃO DO VÍDEO ░░░▒▒▒▓▓▓ ▬▬▬▬▬▬▬▬▬▬▬ஜ۩۞۩ஜ▬▬▬▬▬▬▬▬▬▬▬▬▬ VEJA COMO RESOLVER DE UMA VEZ POR TODAS O ERRO “DEVICE...

Bypass Google Account Protection in ZTE BLADE – How to Remove FRP

March 19, 2020

March 19, 2020 23

This tutorial prestents the best way to remove Google Accout protection. How to bypass Google Account protection? How to remove...

How To Root Vivo V7

March 6, 2020

March 6, 2020 4

FB – Insta – Warning Installing TWRP Recovery, rooting and unlocking bootloader and then flashing the port on your device...

Access Android SQLite database using ADB

March 3, 2020

March 3, 2020 2

Access the SQLite db for your Android app using Android Debug Bridge (ADB) in order to see the currently saved...

Desativar modo test CQA modo avião definitivo moto E5 Plus todos os motorolas

March 18, 2020

March 18, 2020 35

Como remover modo test CQA Desligue o modo avião para fazer uma chamada Aqui pessoal primeiramente deixando os comandos vocês...

How to Scan External Host Names & IP Addresses using Nmap (11/14)

February 23, 2020

February 23, 2020 11

Get The Complete Linux Administration Course Bundle! Enroll in our newest ethical hacking course! In this video we will dig...

Mở hộp Huawei Nova 3i, Review đánh giá nova 3i, đáng giá trong phân khúc 5-6 triệu

February 9, 2020

February 9, 2020 2

TimGiaNgon rất vui mừng khi được sở hữu trên tay, đập hộp điện thoại Huawei Nova 3i – siêu phẩm trong...

How to Mirror Android Phone Broken Screen !!

March 20, 2020

March 20, 2020 36

How to Mirror Android Phone Broken Screen (NO ROOT Required!!): Consider this video as a preventive measure in case you...

Comments
  • greetings, It looks mostly good after performing the update, and home assistant does indeed connect. I did find a problem though with JSON Decoder errors indicating that for example, "Expecting property name enclosed in double quotes" . I noticed that the shell script sqlite3-to-mysql converts all double quotes to backquotes(`) for the conversion and the data in the tables events and states reflect this. I am thinking that to fix this, there needs to be something like the following to fix it:
    update events set event_data = REPLACE(event_data, '`', '"');
    update states set attributes = REPLACE(attributes, '`', '"');

    UPDATE:

    I found that the index current value needs to also be set for the states table. I needed to add the following to my instance:

    elect max(state_id) from states; (IT SHOULD RETURN A NUMBER)
    alter table states modify column state_id int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=183522; (NUMBER RETURNED PREVIOUSLY **INCREASED BY 1)

     would you want to add this to the instructions above?

    Regards

  • How can maintain the ON and OFF switch status in Hassbian? Once I restart my raspberry pi 3 then I lost all the lights / switch status. Is there any way to keep in as it was before restarting?

  • You didn't add the foreign key back. I see there is a typo in the original article, should be:

    ALTER TABLE states ADD CONSTRAINT states_ibfk_1 FOREIGN KEY (event_id) REFERENCES events (event_id);

  • Im having this error after the database is implemented "Error converting row to state: <homeassistant.components.recorder" any idea why?

  • Great video
    On hassbian (Strech) got following error:
    gpg: failed to start the dirmngr '/usr/bin/dirmngr': No such file or directory
    gpg: connecting dirmngr at '/tmp/apt-key-gpghome.wfF9asVRTy/S.dirmngr' failed: No such file or directory
    gpg: keyserver receive failed: No dirmngr

    Fixed it with:
    sudo apt remove gnupg
    sudo apt install –reinstall gnupg2
    sudo apt install dirmngr

  • Adrian, as always great tutorial. What are the advantages of using Maiadb (Mysql or Percona) , vs sqllite. Is there a significant advantage to doing the migration.

    As far as Im concerned, you can say , "Cause I say SO" and that is good enough for me.
    Thanks,
    LL

  • I looked over the documentation for MariaDB after watching your video. Would this allow HA to be configured for multiple logins for different users and have the UI customized per user? Or at least hide some things from a guest user? – and maybe a follow up tutorial to show how?

  • hey man thanks for the video, at the start of your videos can you give a brief explanation of what are the advantages of doing this and why somebody would do it? thanks again

Leave a Reply

Your email address will not be published. Required fields are marked *