MariaDB Addon - access databases

I was wondering how I could easily access the databases created within the MariaDB addon on my host?

Could be a worthwhile addition to the docs https://github.com/home-assistant/addons/blob/8f18676e6aff271cdb2e73222ad2a71ecec5a4b5/mariadb/DOCS.md

Under configuration I see 3306 disabled on the host, but even if I set that to 3306 and SSH tunnel to the host via the addon i cannot connect.

Would this require setting up SSH access to the host in order to do this?

e.g. https://developers.home-assistant.io/docs/operating-system/debugging/#ssh-access-to-the-host

There’s this:

Exposing the port on the host really means exposing to the rest of your network. So if you list 3306 there then from another machine on the same LAN network you should be able to access the DB at <ha host>:3306.

SSHing into the actual host system is very rarely needed and provides no benefit in terms of access to addons.

1 Like

That worked perfectly.

Do you know if there is a “root” user that can be used to see all the databases? or is that outside the scope of the addon?

There is. The addon itself generates the password and sets its details. It does not give users control over it but it has to exist in order to set up databases. Other addons can also request those access details from supervisor if they want or require an existing MySQL service to store their data in (see the Nginx Proxy Manager and Bookstacks addons for example).

If you need superuser access on the DB for a one-off admin task I would suggest using the SSH & Web Terminal addon in the community addons repo. When you disable protection mode on that addon it gives you access to the Docker CLI. So you can get shell access in the MariaDB addon by doing docker exec -it addon_core_mariadb bash. From there you can just directly use the mysql binary. You don’t need any credentials from within that container as its the one running the mariadb service.

If you intend to set up some kind of automated script that needs higher level access then probably best to go into the mariadb container like I outlined above and create a new user with the level of access you need. I wouldn’t use the service operator since it has very broad access and supervisor relies on it, better to create your own and give it exactly the permissions it needs.

EDIT: Wait, I’m overcomplicating this lol. The phpMyAdmin addon tom mentioned above is one of the addons that requests the operator I mentioned. So using that is the easiest way for both of these tasks. That UI is shown with essentially superuser access on the DB.

2 Likes