Recorder external database

Hello,
I am currently trying to move the data to an external database

I have make an Database on my Synology Server.

Now I have add the following to my configuration.yaml:

recorder:
  db_url: mysql://username:password@ip-adresse/phpMyAdmin/homeassistant?charset=utf8mb4

Of course I entered the username, password and IP address correctly.

But after a restart vom homeassistant I got the following two Errors:

  • Setup failed for recorder: Integration failed to initialize.
    13:27:02 – (FEHLER) setup.py

  • Unable to set up dependencies of history. Setup failed for dependencies: recorder

13:27:02 – (FEHLER) setup.py

What must I change, that it works?

Is the version of your database 5.8 or higher ?

Sorry tha I forgot to write here.

The database is MariaDB 10.

Then it should be 10.3 minimum. Is it?

me a bit noob, but this dont feel right. phpMyAdmin should not be part of url afaik.

192.168.1.11/hassdb?charset

is copied from my config

The database version is complete: 10.3.29-1038

I am not sure, because this is the link I use to go to the database.

But I have try it without the phpMyAdmin as follow:

recorder:
  db_url: mysql://uername:password@ip-adress/homeassistant?charset=utf8mb4

But with the same errors.

Any other idea?

yes, just one to check
You need to enable remote access for this user. Per default you can only connect from localhost (same host where mariadb is running)

Ok, know I don´t get errors.

But in the databse are no tables. I think it don´t work or?

Must I creat manually a table und fields?

If yes, witch table name? Witch fields?

If no, what goes wrong?

I don´t know what it go wrong, but now I got with the configoration from above:

recorder:
  db_url: mysql://user:password@ip-adress/homeassistant?charset=utf8mb4

The following errors:

Setup failed for recorder: Integration failed to initialize.
19:17:53 – (FEHLER) setup.py

Unable to set up dependencies of logbook. Setup failed for dependencies: recorder
19:17:53 – (FEHLER) setup.py

I don´t know why I don´t got the errors in my tests before.

Anyone an idea?

You need to check in phpMyAdmin that the privileges for the user allows access to the database externally. By default only users on LOCALHOST can login to the database, unless you remembered to change it when you created the user.

sorry I have missunderstand it before.

Now I I have create a user with hostname = %
I thnik this it is what you mean with externally access

But also the errors:
Setup failed for recorder: Integration failed to initialize.
20:16:44 – (FEHLER) setup.py

Unable to set up dependencies of history. Setup failed for dependencies: recorder
20:16:44 – (FEHLER) setup.py

OK, but have you then allowed that user to have access to the database? And having done all that have you then flushed privileges to apply the new settings?

This would have been MUCH easier - if you had done it using the mysql command directly on the server, typing a few commands, and it would be done and ready.

I am not sure what you mean with “have you then allowed that user to have access to the database?”

I have flushed privileges to apply the new settings.

I don´t know how I do it with a mysql command.

Can you tell me how?

A new user doesn’t automatically have access to any databases, you need to go to the privileges tab, edit the user, scroll down to “database specific privileges” and if the database is already listed under privileges for the user, then click the edit button and ensure that ALL possible privileges have been granted to that user. It needs access to all the privileges under data and structure. Or it can’t create the tables it needs to operate.

You could also add:

logger:
  logs:
    homeassistant.components.recorder: info

to your configuration.yaml so we can get more information about why specifically it is failing to connect. (and info level doesn’t provide enough information, try debug)

The User have all privileges:

I have add the code to my configuration.yaml

And this are showing in the log:

Setup failed for recorder: Integration failed to initialize.

21:42:28 – (FEHLER) setup.py - Die Nachricht ist zum ersten Mal um 21:42:01 aufgetreten und erscheint 5 mal

Unable to set up dependencies of history. Setup failed for dependencies: recorder
21:42:28 – (FEHLER) setup.py

Setup of recorder is taking over 10 seconds.
21:42:17 – (WARNUNG) /usr/local/lib/python3.9/asyncio/events.py

Error during connection setup to mysql://user:mypassword@ip-adress/homeassistant?charset=utf8mb4: (MySQLdb._exceptions.OperationalError) (2002, “Can’t connect to MySQL server on ‘ip-adress’ (115)”) (Background on this error at: Error Messages — SQLAlchemy 1.4 Documentation) (retrying in 3 seconds)
21:41:58 – (FEHLER) Recorder

Ok the last error say, that homeassistant cant connrect to the database. but what must I change now?

OK what is the full URL you are using to connect the recorder to the database? If the IP address is an internal one - you are not putting yourself at risk by posting it here, it’s ONLY external IP addresses that are risky.

yes sure:

here:

db_url: mysql://user:[email protected]/homeassistant?charset=utf8mb4

OK the next thing to ask is what computer is the mysql / mariadb server running on? ie what operating system is it running? It’s possible that port 3306 isn’t open to incoming connections from other machines on the network.

I think I got it:

I have now try this one:
db_url: mysql://user:[email protected]:3307/homeassistant?charset=utf8mb4

Now the table and fields a create.

Is there a posibility to export the old datas and import to the external database?