How to allow multiple Kodi clients to share one media librabry

Last updated: 02/07/2016 - 4 years, 5 months ago

An article tagged as: kodi, mysql, ubuntu

Twitter Facebook Reddit


If you have more than one Kodi device connected to your media source, it becomes really useful if they share the same media library. This is done with a mySQL database on your media server.

Things to do before you start

  • Make sure you have a server that contains all your media files
  • Share your media files across your network using something like samba
  • Make sure you can log into your server using SSH
  • Make sure all your clients that will access your server are running the same version of Kodi
  • Make sure you can log into all your clients using SSH

Set up the server

SSH into the server where your media files are stored.

Configure mySQL

mySQL is used as the database to store your media library.

sudo apt-get update
sudo apt-get install mysql-server

Follow on screen prompts including setting a password. Remember the password for later.

We want to configure mySQL to listen for connections from other computers.

sudo nano /etc/mysql/my.cnf

Change the bind-address to the ip address of your server. Then restart mySQL.

sudo restart mysql

Create Kodi user

Log into the mySQL admin tool.

mysql -u root -p

Create the user that will access the database.


Allow the kodi user permission to access the database.

GRANT ALL ON *.* TO 'kodi';

Set a password for the user

SET PASSWORD FOR 'kodi'@'localhost' = PASSWORD('mykodipassword');

Flush the privileges and exit the database admin tool.

flush privileges;

Check that the new kodi user can log in. Make sure you use the password you just created.

mysql -u kodi -p

If you cannot log-in, please check that you have followed all the above steps.

Set up the client

We will set up one Kodi client to start with. SSH into one of your clients.

Configure mySQL

Make sure that mysql-client is installed.

sudo apt-get update
sudo apt-get install mysql-client

Check that the server is online, then try to connect to it from the client.

mysql -h 192.168.999.666 -u 'kodi' -p 'mykodipassword';

You should now be logged into the server from the client!

Library export

You can export your media library from your client, to be re-imported into your mySQL database. However, this export will create lots of unnecessary files.

Personally, I am going to skip this step, so that my server will do a fresh import of my sources into mySQL.

This will mean losing any watched status, but it will give me a long overdue reason to go through my library.

Set client to use mySQL

We now need to store our mySQL settings on the client. This is done by editing the advancesettings.xml file.

Make a safe copy of your current advanced settings.

cp ~/.kodi/userdata/advancedsettings.xml ~/.kodi/userdata/

Now edit your advancedsettings.xml file.

nano ~/.kodi/userdata/advancedsettings.xml

Add the following sections to the advancedsettings node, using the details of your mySQL setup.


For host, make sure you use an ip address, as not all devices may be able to resolve a host name.

Here is a full advancedsettings.xml file that you can use, again making sure you use your own mySQL settings.


Once everything is working on the client, you can simply repeat the process for each of your Kodi clients.

Library import

Your client is now using mySQL as its database. Unless you did a proper export, I would just clean your library then update it as normal.


You are now using a central mySQL database as your media library.

The next final step is useful to wake up your server when you need it.

Kodibuntu Wake on Lan (WoL)

If you use a linux based client, like Kodibuntu, then you may want to wake your server when Kodi loads. If you use a central mySQL database then you may also want to wait until your client has connected to it before opening Kodi.

We are going to use the script from the madaboutbrighton wol package at GitHub. This script does two things:-

  1. Waits for the network interface of the client to become active, then sends a magic packet to wake a remote computer.
  2. Attempts to connect to mySQL on a remote computer until a response is recieved.

Configure server

We are going to make a dummy mySQL user that the script can use to test the connection.

SSH into your server and create a new dummy mySQL user. Remember the username and password for later.

mysql -u root -p

CREATE USER 'mydummyusername' IDENTIFIED BY 'mydummyusername';
SET PASSWORD FOR 'mydummyusername'@'localhost' = PASSWORD('mydummypassword');

Check that the new dummy user can log in. Make sure you use the password you just created.

mysql -u mydummyusername -p

If you cannot log-in, please check that you have followed all the above steps.

Configure client

Check mySQL from client

SSH into your client and check that it can access mySQL on your server using your dummy credentials.

mysql -h 192.168.999.666 -u 'mydummyusername' -p 'mydummypassword';

Install the script

We want to run each time Kodi loads. Kodibuntu has a live.d folder where scripts can be placed, which are then run as Kodi loads via /etc/init/kodibuntu.conf.

On your client, navigate to the live.d folder.

cd /etc/kodi/live.d
cd /etc/xbmc/live.d

Download the wake on lan script into this directory and make it excecutable.

sudo wget
sudo chmod +x
sudo mv

The script is dependant on having wakeonlan installed.

sudo apt-get update
sudo apt-get install wakeonlan

Edit the script

Open the script so that you can put in your own settings.

sudo nano

Edit SERVER_MAC and SERVER_IP with the MAC and IP address of your server.

Edit MYSQL_USER and MYSQL_PASS with the dummy mySQL username and password that you just set-up on the server. Save your changes ctrl + o and exit nano ctrl + x

Check the script works

sudo ./

If all went well, you should see something like this.

Waiting for client network interface to become active
  -Client network interface is active
Waiting for reply from 192.168.999.666 (MAC - MY:SE:RV:ER:MA:C0)
  -Reply received
Waiting for mySQL on 192.168.999.666
  -Connected to mySQL on 192.168.999.666