Setting Up MySQL in LibreELEC on Raspberry Pi

 Nov. 17, 2017     0 comments

Kodi mediacenter can maintain a common medialibrary on MySQL 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).


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 MySQL database on storage volume:

mkdir /storage/mysql

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 MySQL server:

docker run -d -p 3306:3306 -v /storage/mysql:/var/lib/mysql --restart unless-stopped -e MYSQL_ROOT_PASSWORD=your_pass --name kodi-mysql hypriot/rpi-mysql

This command will download the necessary image from Docker repository (it will take some time) and run MySQL server in a Docker container. The /storage/mysql directory that you have created will be mounted to the container as MySQL database directory. Replace your_pass with your MySQL root password. The --restart unless-stopped option means that Docker will automatically start the container on system boot unless it has been explicitly stopped. The hypriot/rpi-mysql image is meant for Raspberry Pi platform. For other platforms, e.g. x86, use an appropriate image.

5. Enter docker ps command to make sure that your container kodi-mysql is running.

6. Enter

docker exec -it kodi-mysql mysql -u root -p

This command will open an interactive session in MySQL 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 MySQL console.

Now your MySQL database is set up. Follow this Wiki article to set up your Kodi instances to work with MySQL database you have just created.

  DockerKodiMySQLRaspberry Pi