MySQL/Setting up Kodi: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
m (fixed redv element)
 
(86 intermediate revisions by 17 users not shown)
Line 1: Line 1:
{{Frodo updated}}
{{:MySQL/Contents}}
{{notice|Since it seems that using "single file" export/import might be having issues with the image URLs for thumbnails in XBMC v12, this page of the MySQL guide has been recently simplified to say just use multiple file export as a safe method to both update the library to use network paths and to import the library for MySQL.}}{{:HOW-TO:Sync multiple libraries/Contents}}
{{mininav| [[MySQL]] }}
Each device that will be sharing a library will need an advancedsetting.xml file.
Each device that will be sharing a library will need an [[Advancedsettings.xml|advancedsetting.xml]] file.


__TOC__
__TOC__
{{-}}
{{-}}
==Make files accessible over the network==
==Make files accessible over the network==
If you haven't already done so, you will need to make your media files accessible to all your XBMC devices by sharing them on the network through file sharing. XBMC itself or the MySQL server will not share the actual files for this set up. Most operating systems have built-in methods for sharing files, or a [[NAS]] device can be used.
If you haven't already done so, you will need to make your media files accessible to all your Kodi devices by sharing them on the network through file sharing. Kodi itself or the MySQL server will not share the actual files for this setup. Most operating systems have built-in methods for sharing files to the network, or a NAS device can be used.




Most of XBMC's file sharing protocols will work except for UPnP, which does not work with the Library feature.
{{note|
*If you use passwords on your network shares then you will need to copy (or [[MySQL/Sync other parts of Kodi|sync]]) your passwords.xml file from the userdata folder to each Kodi device.
*Do not use mapped drives on the OS-level, as Kodi will see those as local drives.
*If you use smb:// paths, you may want to use static IP addresses rather than NetBIOS names, as not all your devices may be able to resolve the latter.
*'''Even if the media is on the same computer as one of the Kodi instances, you MUST use a network share path. You cannot use a local file path with MySQL.'''}}




See [[:Category:File Sharing]] for some of the file sharing methods that work with XBMC.
See [[:Category:File sharing]] for some of the file sharing methods that work with Kodi.


==Exporting==
{{see also|Backup|Import-export library}}


{{Note|If you use passwords on your network shares then you will need to copy (or [[HOW-TO:Sync multiple libraries/Sync other parts of XBMC|sync]]) your passwords.xml file from the userdata folder to each XBMC device.}}
{{note|You only need to do the exporting steps if you are migrating an existing local library to a MySQL database. The MySQL setup creates an entirely new library on the MySQL server, so this step allows you to preserve your old library and restore it once MySQL is used in Kodi.}}


==MySQL advancedsettings==
{{redv|'''Warning:''' |This will create individual ".nfo" and image files along side your video files. This is considered the safest way to backup and/or migrate a library (MySQL or otherwise), but some users might not want the file clutter.}}
 
#Open Kodi on the computer that has the library you want to share
##Export the Video Library by doing the following:
###Go to '''Settings/Media/Library/Video Library''' and select '''Export library'''
###Select '''Multiple files'''
 
 
##Export the Music Library by doing the following:
###Go to ''''Settings/Media/Library/Music Library''' and select '''Export library'''
###Select '''Multiple files'''
 
==MySQL and advancedsettings.xml==
{| class=infobox
{| class=infobox
| advancedsettings.xml:
| advancedsettings.xml:
|-
|-
|
|
<pre><advancedsettings>
<syntaxhighlight lang=xml>
    <videodatabase>
<advancedsettings>
        <type>mysql</type>
  <videodatabase>
        <host>***.***.***.***</host>
    <type>mysql</type>
        <port>3306</port>
    <host>***.***.***.***</host>
        <user>xbmc</user>
    <port>3306</port>
        <pass>xbmc</pass>
    <user>kodi</user>
    </videodatabase>  
    <pass>kodi</pass>
 
  </videodatabase>  
    <musicdatabase>
  <musicdatabase>
        <type>mysql</type>
    <type>mysql</type>
        <host>***.***.***.***</host>
    <host>***.***.***.***</host>
        <port>3306</port>
    <port>3306</port>
        <user>xbmc</user>
    <user>kodi</user>
        <pass>xbmc</pass>
    <pass>kodi</pass>
    </musicdatabase>
  </musicdatabase>
 
  <videolibrary>
    <videolibrary>
    <importwatchedstate>true</importwatchedstate>
          <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
    </videolibrary>
  </videolibrary>
</advancedsettings></pre>
</advancedsettings>
</syntaxhighlight>
<small>''See also this note about using the <name> tag: [[#Name tag]]<br/><importwatchedstate> is only needed when you're importing a previous library from exported files.</small>
<small>''See also this note about using the <name> tag: [[#Name tag]]<br/><importwatchedstate> is only needed when you're importing a previous library from exported files.</small>
|}
|}
#Open XBMC on the computer that has the library you want to share ''(If you have not created a library yet you can skip this step)''
#Create (or add to, if you already have one) an [[Advancedsettings.xml#.3Cmusicdatabase.3E.2F.3Cvideodatabase.3E|advancedsettings.xml]] file:
##Export the Video Library by doing the following:
###Go to '''System/Settings -> Video -> Library''' and select '''Export library'''
###Select '''Multiple files'''
##Export the Music Library by doing the following:
###Go to '''System/Settings -> Music -> Library''' and select '''Export library'''
###Select '''Multiple files'''
#Create (or add to, if you already have one) an advancedsettings.xml file:
##Open up a plain text editor
##Open up a plain text editor
##Copy and paste the text from the right-hand box into a new text document
##Copy and paste the text from the right-hand box into a new text document
##Replace the two instances of <code>***.***.***.***</code> with local network IP address of your MySQL server
##Replace the two instances of <code>***.***.***.***</code> with local network IP address of your MySQL server. If you installed MySQL on a Windows machine, do not use its NetBIOS name, as not all devices may be able to resolve them.
##Save the file as '''advancedsettings.xml'''
##Save the file as '''advancedsettings.xml'''
#Copy this ''advancedsettings.xml'' file you just created to the userdata folder of every XBMC install you want to sync with:
#Copy this ''advancedsettings.xml'' file you just created to the '''[[Userdata]]''' of every Kodi install you want to sync with.
#* '''Windows XP:''' <code>Documents and Settings\<your_user_name>\Application Data\XBMC\userdata\advancedsettings.xml</code>
{{-}}
#* '''Vista/Windows 7:''' <code>Users\<your_user_name>\AppData\Roaming\XBMC\userdata\advancedsettings.xml</code>
 
#* '''Mac OS X:''' <code>/Users/<your_user_name>/Library/Application Support/XBMC/userdata/advancedsettings.xml</code>
{{note|Sometimes it takes your dhcp too long before an ip-address is assigned to the local machine and the [https://github.com/samnazarko/osmc/issues/131 mysql driver are therefore not loaded]. In this case the library will appear empty and will not show resumepoints and watchedstates. In that case run <code>sudo systemctl enable connman-wait-for-network.service</code> on the shell or look for the option "wait for a network connection before loading" in the network options}}
#* '''iOS:''' <code>/private/var/mobile/Library/Preferences/XBMC/userdata/advancedsettings.xml</code>
 
#* '''Linux:''' <code>$HOME/.xbmc/userdata/advancedsettings.xml</code>
==Importing==
#Open any of your XBMC installs and re-import your library data ''(If you have not created a library yet you can skip this step)''
At this point Kodi is using the MySQL server for the database, which means it has a new blank library. Now we can either import an old library (see below) or simply start a new library (see [[HOW-TO:Create_Video_Library]]). From this point on, Kodi behaves exactly like it would as if it had a local database, except that database is on the MySQL server and multiple installs can access that single database.
##Import the Video Library by doing the following: Add the networked video source to XBMC and scan it in as if you were setting up your library for the first time (see [[adding videos to the library]]). However, XBMC will read the exported nfo files and images and use those instead of rebuilding the library from scratch. The end result will be an identical library, and your watched status for videos will be preserved.
 
##Import the Music Library by doing the following: Same idea as videos, but using the steps for [[adding music to the library]]. You'll end up with an identical library.
 
#You can now add files and update the library from any of your XBMC devices and the library for all of them will stay in sync.
# Open any of your installs and re-import your library data, ''or'' simply set up a new library if you are starting fresh.
# Add (or just "set content" on) the networked video source to Kodi and scan it in as if you were setting up your library for the first time (see [[HOW-TO:Create_Video_Library|adding videos to the library]]). However, Kodi will read the exported nfo files and images and use those instead of rebuilding the library from scratch. The end result will be an identical library, and your watched status for videos will be preserved.
#:{{Note|You must add a network source using Kodi's standard formatting. For example, use "smb://192.168.1.20/Videos/" and not "\\BOBPC\Videos\".  Try to use static IP addresses over NetBIOS names if using SMB.}}
# Import the Music Library by doing the following: Same idea as videos, but using the steps for [[HOW-TO:Create_Music_Library|adding music to the library]]. You'll end up with an identical library.
You can now add files and update the library from any of your devices and the library for all of them will stay in sync.
 
== Adding new Kodi devices to the MySQL setup ==
Since the database has now been set up on the MySQL server, all you need to do for any additional Kodi devices, is to copy a small number of files/folders.
* Copy the MySQL connections section for video and/or music databases into the '''advancedsettings.xml''' file on the other Kodi client(s). If you have identical Kodi devices, simply copy the whole advancedsettings.xml file from the initially setup Kodi device.
* Copy from the same userdata root folder the files, such as "'''favourites.xml'''", "'''sources.xml'''", "'''mediasources.xml'''", "'''passwords.xml'''" (if present).
 
 
To have the other Kodi client(s) also benefit from the already downloaded/cached art thumbnails:
* Copy the '''Textures13.db''' file from the '''userdata/Database folder''' to the other Kodi client(s).
* Copy the full '''Thumbnails''' subfolder from the userdata folder to other Kodi client(s). (This subfolder may contain several megabytes of small files when dealing with large video/music collections)
 


You don't need to do any of the other steps, such as rescanning or reimporting. Any fanart not already cached will be downloaded shortly after. If this method works on one device, it should work on all of them, as they are basically sharing the same "brain" for the video/music metadata.


:{{note|If you want to update the library from any of the XBMC devices then they must all have the same sources set. See '''[[HOW-TO:Sync multiple libraries/Sync other parts of XBMC|the Sources section of Part 6]]''' for one method of keeping them in sync.}}
If you however used a metadata collector add-on ([[Scrapers|scraper]]) that does not ship by default with new installations, such as the [[Add-on:Universal Movie Scraper|Universal Movie Scraper]] you will not be able to display the [[Basic_controls|media information screen]] on the new Kodi device. To fix that, you need to install the same metadata collector add-on on the new device.
:{{note|If you encounter error 1062, then you'll need to change your paths from "\\" to "//" as MySQL has trouble understanding "\\"}}
:{{note|If you are using Eden, the video MySQL database will have 60 appended to the name (ex. video_database60). The music MySQL database will have 18 appended to the name (ex. music_database18).}}


==Name tag==
==Name tag==
<section begin="name tag" />
<section begin="name tag" />
An additional <code><name></code> tag can be used for both the video and music entries in advancedsettings.xml if you want to change the name of the database.
An additional <code><name></code> tag can be used for both the <code><videodatabase></code> and <code><musicdatabase></code> entries in advancedsettings.xml file, if you want to change the name of the database. The <code><name></code> tag is not required. Kodi will use "MyVideos" and "MyMusic" as database names if the <code><name></code> tag is not specified.  


The name tag is not required (XBMC will use a default "MyVideos" and "MyMusic" DB name) and it is recommended to not include it if you only need one library, as some users have reported problems/bugs when it was included.
You may want to do this if you want to have multiple separate libraries (with different content) on the same MySQL server. For example, if you want to create multiple profiles, each with their own shared library, so that each Kodi device can "log-into" that library. (a kids library, a guest library, etc)


The tag is only needed if you want to have separate databases on the same MySQL server, like for more than one shared library. For example, if you want to create multiple profiles, each with their own shared library, so that each XBMC device can "log-into" that library.
{{note|Don't try to merge the video and music databases! You need to use different values in the <code><name></code> tag or you'll end up confusing Kodi leading to the library functionality not working at all. In other words, don't use <code><name>Kids</name></code> for both music and videos, but instead use something like <code><name>Kids-music</name></code> and <code><name>Kids-video</name></code>.}}


{{editor note|eventually we'll have a better section for explaining the <name> tag. Until then, check out the alternative MySQL guide from howtogeek.com, which does dive into using the <name> tag for multiple databases and even profiles: [http://www.howtogeek.com/75535/how-to-sync-your-media-across-your-entire-house-with-xbmc/ How to Sync Your Media Across Your Entire House with XBMC].}}<section end="name tag" />
{{Krypton updated}}

Latest revision as of 16:45, 20 April 2023

Share libraries w/MySQL, guide:

  1. Introduction
  2. Setting up MySQL
  3. Setting up Kodi
Home icon grey.png   ▶ MySQL ▶ Setting up Kodi

Each device that will be sharing a library will need an advancedsetting.xml file.


Make files accessible over the network

If you haven't already done so, you will need to make your media files accessible to all your Kodi devices by sharing them on the network through file sharing. Kodi itself or the MySQL server will not share the actual files for this setup. Most operating systems have built-in methods for sharing files to the network, or a NAS device can be used.


Note:

  • If you use passwords on your network shares then you will need to copy (or sync) your passwords.xml file from the userdata folder to each Kodi device.
  • Do not use mapped drives on the OS-level, as Kodi will see those as local drives.
  • If you use smb:// paths, you may want to use static IP addresses rather than NetBIOS names, as not all your devices may be able to resolve the latter.
  • Even if the media is on the same computer as one of the Kodi instances, you MUST use a network share path. You cannot use a local file path with MySQL.


See Category:File sharing for some of the file sharing methods that work with Kodi.

Exporting

Note: You only need to do the exporting steps if you are migrating an existing local library to a MySQL database. The MySQL setup creates an entirely new library on the MySQL server, so this step allows you to preserve your old library and restore it once MySQL is used in Kodi.

Warning: This will create individual ".nfo" and image files along side your video files. This is considered the safest way to backup and/or migrate a library (MySQL or otherwise), but some users might not want the file clutter.


  1. Open Kodi on the computer that has the library you want to share
    1. Export the Video Library by doing the following:
      1. Go to Settings/Media/Library/Video Library and select Export library
      2. Select Multiple files


    1. Export the Music Library by doing the following:
      1. Go to 'Settings/Media/Library/Music Library and select Export library
      2. Select Multiple files

MySQL and advancedsettings.xml

advancedsettings.xml:
<advancedsettings>
  <videodatabase>
    <type>mysql</type>
    <host>***.***.***.***</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </videodatabase> 
  <musicdatabase>
    <type>mysql</type>
    <host>***.***.***.***</host>
    <port>3306</port>
    <user>kodi</user>
    <pass>kodi</pass>
  </musicdatabase>
  <videolibrary>
    <importwatchedstate>true</importwatchedstate>
    <importresumepoint>true</importresumepoint>
  </videolibrary>
</advancedsettings>

See also this note about using the <name> tag: #Name tag
<importwatchedstate> is only needed when you're importing a previous library from exported files.

  1. Create (or add to, if you already have one) an advancedsettings.xml file:
    1. Open up a plain text editor
    2. Copy and paste the text from the right-hand box into a new text document
    3. Replace the two instances of ***.***.***.*** with local network IP address of your MySQL server. If you installed MySQL on a Windows machine, do not use its NetBIOS name, as not all devices may be able to resolve them.
    4. Save the file as advancedsettings.xml
  2. Copy this advancedsettings.xml file you just created to the Userdata of every Kodi install you want to sync with.


Note: Sometimes it takes your dhcp too long before an ip-address is assigned to the local machine and the mysql driver are therefore not loaded. In this case the library will appear empty and will not show resumepoints and watchedstates. In that case run sudo systemctl enable connman-wait-for-network.service on the shell or look for the option "wait for a network connection before loading" in the network options

Importing

At this point Kodi is using the MySQL server for the database, which means it has a new blank library. Now we can either import an old library (see below) or simply start a new library (see HOW-TO:Create_Video_Library). From this point on, Kodi behaves exactly like it would as if it had a local database, except that database is on the MySQL server and multiple installs can access that single database.


  1. Open any of your installs and re-import your library data, or simply set up a new library if you are starting fresh.
  2. Add (or just "set content" on) the networked video source to Kodi and scan it in as if you were setting up your library for the first time (see adding videos to the library). However, Kodi will read the exported nfo files and images and use those instead of rebuilding the library from scratch. The end result will be an identical library, and your watched status for videos will be preserved.
    Note: You must add a network source using Kodi's standard formatting. For example, use "smb://192.168.1.20/Videos/" and not "\\BOBPC\Videos\". Try to use static IP addresses over NetBIOS names if using SMB.
  3. Import the Music Library by doing the following: Same idea as videos, but using the steps for adding music to the library. You'll end up with an identical library.

You can now add files and update the library from any of your devices and the library for all of them will stay in sync.

Adding new Kodi devices to the MySQL setup

Since the database has now been set up on the MySQL server, all you need to do for any additional Kodi devices, is to copy a small number of files/folders.

  • Copy the MySQL connections section for video and/or music databases into the advancedsettings.xml file on the other Kodi client(s). If you have identical Kodi devices, simply copy the whole advancedsettings.xml file from the initially setup Kodi device.
  • Copy from the same userdata root folder the files, such as "favourites.xml", "sources.xml", "mediasources.xml", "passwords.xml" (if present).


To have the other Kodi client(s) also benefit from the already downloaded/cached art thumbnails:

  • Copy the Textures13.db file from the userdata/Database folder to the other Kodi client(s).
  • Copy the full Thumbnails subfolder from the userdata folder to other Kodi client(s). (This subfolder may contain several megabytes of small files when dealing with large video/music collections)


You don't need to do any of the other steps, such as rescanning or reimporting. Any fanart not already cached will be downloaded shortly after. If this method works on one device, it should work on all of them, as they are basically sharing the same "brain" for the video/music metadata.

If you however used a metadata collector add-on (scraper) that does not ship by default with new installations, such as the Universal Movie Scraper you will not be able to display the media information screen on the new Kodi device. To fix that, you need to install the same metadata collector add-on on the new device.

Name tag

An additional <name> tag can be used for both the <videodatabase> and <musicdatabase> entries in advancedsettings.xml file, if you want to change the name of the database. The <name> tag is not required. Kodi will use "MyVideos" and "MyMusic" as database names if the <name> tag is not specified.

You may want to do this if you want to have multiple separate libraries (with different content) on the same MySQL server. For example, if you want to create multiple profiles, each with their own shared library, so that each Kodi device can "log-into" that library. (a kids library, a guest library, etc)

Note: Don't try to merge the video and music databases! You need to use different values in the <name> tag or you'll end up confusing Kodi leading to the library functionality not working at all. In other words, don't use <name>Kids</name> for both music and videos, but instead use something like <name>Kids-music</name> and <name>Kids-video</name>.