Overview
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.
CREATE USER 'kodi' IDENTIFIED BY 'kodi';
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;
\q
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/advancedsettings.xml.safe
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.
<videodatabase>
<type>mysql</type>
<host>192.168.999.666</host>
<port>3306</port>
<user>kodi</user>
<pass>mykodipassword</pass>
</videodatabase>
<musicdatabase>
<type>mysql</type>
<host>192.168.999.666</host>
<port>3306</port>
<user>kodi</user>
<pass>mykodipassword</pass>
</musicdatabase>
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.
<advancedsettings>
<useddsfanart>true</useddsfanart>
<cputempcommand>cputemp</cputempcommand>
<gputempcommand>gputemp</gputempcommand>
<samba>
<clienttimeout>30</clienttimeout>
</samba>
<network>
<disableipv6>true</disableipv6>
</network>
<videolibrary>
<importwatchedstate>true</importwatchedstate>
<importresumepoint>true</importresumepoint>
</videolibrary>
<videodatabase>
<type>mysql</type>
<host>192.168.999.666</host>
<port>3306</port>
<user>kodi</user>
<pass>mykodipassword</pass>
</videodatabase>
<musicdatabase>
<type>mysql</type>
<host>192.168.999.666</host>
<port>3306</port>
<user>kodi</user>
<pass>mykodipassword</pass>
</musicdatabase>
</advancedsettings>`]]
Once everything is working, 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.
Congratulations
You are now using a central mySQL database as your media library.