Updated on 2010-06-13
Kodi mediacenter can maintain a common medialibrary on MySQL/MariaDB database server. This way a media library, including "watched" and "in progress" marks, can be synchronized between several Kodi instances. The official Kodi Wiki provides instructions on how to set up MySQL server on various platforms, however those instructions do not include LibreELEC — a popular mediacenter software based on Kodi that runs on various platforms, including different versions of Raspberry Pi single-board computers.
LibreELEC is basically Kodi running on top of a stripped-down variant of Linux OS. LibreELEC does not include any packet manager that allows to install third-party software, so installing MySQL is not a straightforward task. However, some Linux programs can be installed as Kodi addons (a special feature of Kodi for LibreELEC that is not available on other platforms). In fact, there is an unofficial LAMP addon (Linux, Apache, MySQL, PHP) that includes MySQL server, but, in my opinion, this addon is redundant if you need just a shared Kodi medialibrary.
Another option of installing MySQL server on LibreELEC is using a Docker container. LibreELEC provides a binary Docker addon for all platforms, including Raspberry Pi, so this method can be applied on x86 as well (I'm not sure if there are MySQL Docker images for other hardware platforms).
Instead of proper MySQL you can use MariaDB that is a compatible fork of MySQL from the original MySQL authors. Kodi supports both. MariaDB uses the same console and SQL commands as MySQL so the procedure is the same for both database servers.
1. In Kodi on LibreELEC go to Add-ons > Install from repository > LibreELEC Add-ons > Services > Docker and install Docker addon.
2. Connect to your LibreELEC machine via ssh using PyTTY or similar program.
3. Create a directory for your MariaDB database on
This step is optional and you can let Docker manage container's data, but it's better to have your database files available outside the container, e.g. for backup purposes.
4. Start a Docker container with MariaDB server:
docker run -d -p 3306:3306 -v /storage/mysql:/var/lib/mysql --restart unless-stopped -e MYSQL_ROOT_PASSWORD=your_pass --name kodi-mariadb yobasystems/alpine-mariadb
This command will download the necessary image from Docker repository (it will take some time) and run MariaDB server in a Docker container. The
/storage/mysql directory that you have created will be mounted to the container as MariaDB database directory. Replace
your_pass with your MariaDB root password. The
--restart unless-stopped option means that Docker will automatically start the container on system boot unless it has been explicitly stopped.
docker ps command to make sure that your container
kodi-mariadb is running.
docker exec -it kodi-mariadb mysql -u root -p
This command will open an interactive session in MariaDB console inside the container.
7. Enter the following commands:
GRANT ALL ON *.* TO 'kodi'@'%' IDENTIFIED BY 'kodi'; FLUSH PRIVILEGES;
Note semicolons (
;) at the end of SQL statements. Enter
exit; to leave the MariaDB console.
Now your MariaDB database is set up. Follow this Wiki article to set up your Kodi instances to work with MariaDB database you have just created.
Note: This article has been updated on 2020-06-13. Instead of abandoned
hypriot/rpi-mysql Docker image it is recommended to use
yobasystems/alpine-mariadb image that is actively maintained (at least for now).