MySQL can no longer scan or play your media after your IP address has changed

If you ever need to migrate your shared media library to a new host or you simply change your router and your new router uses a different subnet to your existing one then you’ll find that Kodi can no longer scan your library or indeed play any of the content from that library. Your Kodi player may get stuck on the splash screen. You may also find it displays a Preparing message and then hangs. Either way, the fix is a multi-step process as the IP address of your server is stored in several different places.

First off, we need to make changes on the media player itself which, in my case, is a mini pc.

Update the advancedsettings.xml file

You need to SSH onto your kodi player and update a file called advancedsettings.xml. So:

vi /storage/.kodi/userdata/advancedsettings.xml

My file looks like this so I would change all occurrences of 192.168.1.200 to be the ip address of the new media server host:

<advancedsettings>
    <videodatabase>
        <type>mysql</type>
        <host>192.168.1.200</host>
        <port>3306</port>
        <user>kodi</user>
        <pass>****</pass>
    <name>MasterVideo</name>
    </videodatabase>

    <musicdatabase>
        <type>mysql</type>
        <host>192.168.1.200</host>
        <port>3306</port>
        <user>kodi</user>
        <pass>****</pass>
    <name>MasterMusic</name>
    </musicdatabase>
    <videolibrary>
      <importwatchedstate>true</importwatchedstate>
      <importresumepoint>true</importresumepoint>
    </videolibrary>
</advancedsettings>

To save your changes press the [Esc] key once and type :wq to save and quit out of the file. If you make a mistake, then issue :q! instead of :wq to abort your changes.

Update the mediasources.xml file

The next file we need to change is the mediasources.xml file. So:

vi .kodi/userdata/mediasources.xml

and make the required changes to that file too.

Update the sources.xml file

Another file that needs changing is the sources.xml file:

vi .kodi/userdata/sources.xml

The start of my file looks like this:

<sources>
    <programs>
        <default pathversion="1"></default>
    </programs>
    <video>
        <default pathversion="1"></default>
        <source>
            <name>Childrens</name>
            <path pathversion="1">smb://192.168.1.200/TV Shows/Childrens/</path>
            <allowsharing>true</allowsharing>
        </source>
        <source>
            <name>Family</name>
            <path pathversion="1">smb://192.168.1.200/TV Shows/Family/</path>
            <allowsharing>true</allowsharing>
        </source>

How to search and replace using vi

As you can see in the above file snippet, there are multiple instances of the server IP address that need to be changed. The easiest thing to do is a global search and replace rather than changing each path individually. So, when you’re in the file press the [Esc] key and type the following:

:%s/apples/oranges/g

This will change all occurrences of apples to oranges. So, if my ip address had changed from 192.168.1.200 to 192.168.10.239 I would type the following:

:%s/192.168.1.200/192.168.10.239/g

As above, to save your changes press the [Esc] key once and type :wq to save and quit out of the file. If you make a mistake, then issue :q! instead of :wq to abort your changes.

The last file we need to change is the passwords.xml file:

vi .kodi/userdata/passwords.xml

If you have a separate library per family member

If you have multiple profiles then you need to change the files for each of the profiles:

As above, the old IP address is stored in multiple files. For each profile you need to change the sources.xml and advancedsettings.xml files:

vi .kodi/userdata/profiles/UserA/sources.xml

vi .kodi/userdata/profiles/UserA/advancedsettings.xml

Also, if you have multiple media players you obviously need to make these changes on each of them.

How to update MySQL when the IP address of your Kodi media server has changed

Now we have finished making the changes on the media players themselves we need to change the MySQL databases as they also have the old IP address in them. There are a LOT of guides out there explaining how to update MySQL and Kodi when the IP address has changed. Many are complicated to follow, others simply don’t work! Or, more accurately, they probably do for the particular Kodi/MySQL version combo. What I recommend is to export everything to flat text files, do a few search and replaces and then import everything back into MySQL. That way the versions of MySQL or Kodi are not relevant as you’re changing plain text files! So,

Take a backup of your existing MySQL databases before you start:

sudo cp -a /var/lib/mysql/. /mysql-backup/

Next, use the MySQLDump function to export all your tables. I recommend exporting everything tather than trying to cherry pick the parts you actually need:

mysqldump -u root -p --all-databases >media_dump.txt

Depending on the size of your media library this will either take a few seconds or a few minutes to complete. Once it’s finished it will have produced a text file called media_dump.txt. This is the file we now need to edit:

vi media_dump.txt

Do a global search and replace of your old and new IP address as detailed above then quit and save the file.

Now, to read the file back into MySQL to replace your existing databases and tables with the updated data we need to issue the following command:

mysql -u root -p < media_dump.txt

As above, this may take a while to complete.

After a quick reboot everything should start working again!