Home » HTPC » Kodi MySQL setup for sharing media library
HTPC

Kodi MySQL setup for sharing media library

Kodi MySQL setup allows you to share your media library, its meta data, and watched status, with other Kodi / XBMC boxes in your network. This allows you to pause on one device and continue on another. Kodi device includes any device that runs a media center OS with Kodi, including OpenELEC, Xbian, Raspbmc, or the newer OSMC. This would also mean that you do not have to maintain, scan, and update multiple Kodi libraries. In our recent, Plex vs Kodi comparison, one of the biggest advantages of Plex was its centralized media server that keeps all devices in sync. Setting up Kodi MySQL database sharing will overcome that limitation. So let us see how Kodi MySQL setup is done.

Requirements for Kodi MySQL Setup

First of all, if you are using only one Kodi device there is no reason to setup Kodi MySQL library sharing. To share Kodi library with other devices, you will need access to a MySQL database server. You may setup a LAMP Server with Ubuntu, which is one of the most common uses of a home server. If you are not comfortable with commandline work, you may also need to setup a GUI such as phpMyAdmin for your MySQL server. If you do not have or want to setup a local MySQL server then you may use an externally hosted MySQL database but that is a topic for another post.

Here are the complete requirements for Kodi MySQL Setup:

  • Kodi Device – any device running Kodi on any operating system
  • Every XBMC/Kodi “client” must run the same version of XBMC/Kodi. But Kodi could be on different operating systems. All minor updates within a same version (14.1, 14.2 in Kodi or 5.0.1, 5.0.2, etc. in OpenELEC) should work together successfully. Check the database version table to ensure that the Video DB and Music DB version numbers are the same for the different Kodi versions you are using.
  • MySQL database server

Assuming that you have all of the above ready, let us look at how to setup a XBMC shared database with MySQL. I will show Kodi MySQL setup using both commandline and phpMyAdmin and you choose which one to follow. If you have another MySQL GUI such as Adminer, that should work too.

1. Export Local Library

I strongly suggest recreating your media library from scratch on MySQL (just personal preference). If you want to do that skip this step. But if you would like to not go through re-scanning your entire library then you may export your current library for importing later into your MySQL media library. Go to Settings->Video->Library and click “Export video library”.

Export Kodi Library
Export Kodi Library

In the questions that follow, answer as shown below.

Export to a single file or separate files per entry? – Separate
Export thumbnails and fanart? – Yes
Export actor thumbnails? – Yes
Overwrite old files? – Yes

Same way, export the your Music library as well. If you have any questions or you want to understand how Kodi media library exporting and importing work, check Kodi Wiki. Once done, exit Kodi.

2. Customize Local MySQL Server

If you are not on the system running the MySQL server, then you may have to SSH into your remote server. Open commandline and edit the /etc/mysql/my.cnf file.

sudo nano /etc/mysql/my.cnf 

Find the line that says bind-address = 127.0.0.1 and comment it out by adding a # in front. Then right blow that add another line that says bind-address = 0.0.0.0, as shown in the picture below.

Edit MySQL Bind Address
Edit MySQL Bind Address

Restart your MySQL server using sudo restart mysql command for changes to take effect. Your MySQL server will now accept connection from remote clients.

3. Setup Kodi / XBMC Shared Database

The next step is to setup your MySQL database for Kodi library sharing. I am going to show both commandline and phpMyAdmin setup (you only need to follow one). If you are using phpMyAdmin on your own server, you may want to implement a few of the phpMyAdmin tweaks.

3.1 Commandline MySQL Setup

Connect to your MySQL Server using the following command:

mysql -u root -p

When asked, type in your password for the MySQL root user and press enter. You should now be in the MySQL prompt that looks like mysql>. Now let us create a user that Kodi will use to access your Kodi / XBMC shared database. At the MySQL prompt, type the commands listed below in sequence. Replace all KodiUser and KodiPassword instances with your desired username and password, respectively, for database access.

CREATE USER 'KodiUser' IDENTIFIED BY 'KodiPassword';
GRANT ALL ON `MyVideos%`.* TO 'KodiUser';
GRANT ALL ON `MyMusic%`.* TO 'KodiUser';
FLUSH PRIVILEGES;
quit

The first command creates the user that will access the Kodi shared database and the second command provides the user with all privileges to only the databases created by Kodi (MyVideosXX and MyMusicXX – XX is the database version). This provides better security as this Kodi database user will not have access to other databases you may have. Note that MyVideosXX and MyMusicXX are the default names used by Kodi (recommended). If you use a different database name than the default ones, then you will have to replace MyVideos% and MyMusic% in the above code block with your custom database names. A successful execution of the above commands should produce an output as shown in the screenshot below.

Kodi MySQL User and Privileges
Kodi MySQL User and Privileges

Continue to next page to complete Kodi MySQL setup…

About the author

Anand

Anand is a self-learned computer enthusiast, a part-time blogger, and a Food Scientist by career. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, XBMC, and related HOW-TOs (read more).

Archives

Join the other 110,000 followers