MySQL: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>Jester
mNo edit summary
 
(110 intermediate revisions by 11 users not shown)
Line 1: Line 1:
{{divbox|navy|radius=4em||'''Requirements:''' These instructions require the latest nightly builds of XBMC (pre-Eden v11). Make sure all your XBMC devices are on the same build date (or at least close).}}
{{divbox|orange||<big>'''NOTICE:''' This is considered an advanced (complicated) and experimental feature.</big>}}
{{XBMC wiki toc}}
{{divbox|red||{{huge|'''NOTICE:''' Every {{kodi}} "client" '''must''' run the same version of {{kodi}}.}}<br />Otherwise they will not be sharing the same library. There can even be differences between [[development builds]], so make sure you always use the same build dates. See '''[[Databases#Database_Versions|Version table]]''' for more info. }}
If you have more than one XBMC device on your local network then you might want to synchronize them using a MySQL library. Using a MySQL library allows you to store information about your whole video library in a central database, so that multiple XBMC devices can access the same information at the same time. This gives you the ability to:
{{:MySQL/Contents}}
{{See also|Databases}}
 
[[File:Network.png|200px|left]]
;<big><u>Introduction</u></big>
<section begin="intro"/>If you have more than one {{kodi}} device on your local network then you might want to synchronize them by sharing the Kodi library databases via the MySQL protocol. Using shared library databases allows you to store information for either your video or music library in a central database, so that multiple devices can access the same information at the same time.<section end="intro"/>
 
This gives you the ability to do things like:
* Share watched and unwatched status for your media on all devices
* Share watched and unwatched status for your media on all devices
* Stop watching a movie or TV show in one room then finish watching it in another room automatically
* Stop watching a movie or TV show in one room then finish watching it in another room automatically
* Only one library to maintain for all devices
* Only one library to maintain for all devices
* Consolidate thumbnails and fanart to save hard drive space
{{-}}
 
== Share your files ==
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. Most of XBMC's file sharing protocols will work except for UPnP.
 
 
See [[:Category:File Sharing]] for some of the file sharing methods that work with XBMC.
 
== Setting up the MySQL server ==
You'll need to choose which of your computers, XBMC devices, or [[NAS]] will be the MySQL server. The server needs to be on 24/7 or have wake-on-lan (preferably the former), and needs to have a local static IP. You will probably want the XBMC device that is hosting most or all of your videos and music to also be the MySQL server, but this is not required.
 
=== On a computer ===
{{incomplete}}
MySQL can be installed on just about every major OS:
#Install MySQL server
#*'''Windows/Mac OS X:''' Download a copy of MySQL server from http://dev.mysql.com/downloads/mysql/
#*'''Linux:''' <code>$sudo apt-get install mysql-server</code> ''(see also: https://help.ubuntu.com/10.04/serverguide/C/mysql.html )''
#Run the installer and select the ''Standard configuration'' {{editor note|<- left over from the lifehacker article. Is this a Windows only thing? Does it still give the option of configurations?}}
#Create a password when asked
#Give the database access to your network:
#*'''Linux:''' Comment out the following line in the MySQL configuration file (/etc/mysql/my.cnf)
#:#from: <code>bind-address = 127.0.0.1</code>
#:#to    : <code>#bind-address = 127.0.0.1</code>
#*'''Mac OS X:'''
#*'''Windows:''' Select that you want the database to have network access when prompted during installation.
#Get into the MySQL command line interface:
#*'''Linux:''' <code>$mysql -u root -p</code>
#*'''Mac OS X:'''
#*'''Windows:''' Open the "MySQL Command Line Client" from the MySQL start menu
#Enter the following commands:
##Type in: <code>CREATE USER 'xbmc' IDENTIFIED BY 'xbmc';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'xbmc';</code> and press return
#:{{editor note|1=Note these "speed up" commands here -> http://xbmcstuff.bossanova808.net/2011/03/summary-of-xbmc-mysql-database.html?m=1 }}
#Close out the command line tool
 
=== On a NAS ===
MySQL can also be installed on some [[w:network-attached storage|network-attached storage (NAS)]] device devices. See one of the following guides for more info:
*[http://www.vectorsigmastudios.com/index.php?page=tutorial&id=2 Pogoplug for a MySQL db in XBMC]
*[http://ozymandyaz.blogspot.com/2011/08/configure-synology-nas-as-mysql-server.html Synology NAS as MySQL server for XBMC]
 
== Setting up XBMC ==
{| class=infobox
| advancedsettings.xml:
|-
|
<pre><advancedsettings>
    <videodatabase>
        <type>mysql</type>
        <host>***.***.***.***</host>
        <port>3306</port>
        <user>xbmc</user>
        <pass>xbmc</pass>
        <name>xbmc_video</name>
    </videodatabase>
 
    <musicdatabase>
        <type>mysql</type>
        <host>***.***.***.***</host>
        <port>3306</port>
        <user>xbmc</user>
        <pass>xbmc</pass>
        <name>xbmc_music</name>
    </musicdatabase>
</advancedsettings></pre>
|}
#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)''
#:'''Notice:''' If your existing library was set up with local file paths rather than network shares, then you will need to follow the '''[[/conversion guide|conversion guide]]''' {{editor note|<-- need help expanding here}} in addition to sharing the files on the network.
##Export the Video Library by doing the following:
###Go to '''System/Settings -> Video -> Library''' and select '''Export library'''
###Select '''Single file'''
##Export the Music Library by doing the following:
###Go to '''System/Settings -> Music -> Library''' and select '''Export library'''
###Select '''Single file'''
#Create (or add to, if you already have one) an advancedsettings.xml file:
##Open up a plain text editor
##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
##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:
#* '''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>
#* '''iOS:''' <code>/private/var/mobile/Library/Preferences/XBMC/userdata/advancedsettings.xml</code>
#* '''Linux:''' <code>$HOME/.xbmc/userdata/advancedsettings.xml</code>
#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)''
##Import the Video Library by doing the following:
###Go to '''System/Settings -> Video -> Library''' and select '''Import library'''
###Select the file you saved from the first step when you exported your video library
##Import the Music Library by doing the following:
###Go to '''System/Settings -> Music -> Library''' and select '''Import library'''
###Select the file you saved from the first step when you exported your music 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.
{{editor note|mention that all XBMC devices must have the same sources (network paths), or at least sources that have "content set", for files/library to be updated from any XBMC device. Maybe even pathsubstitution for sources.xml? (or save that for some "total sync" guide?)}}
 
== Syncing thumbnails and fanart ==
While syncing thumbnails and fanart is not required for sharing multiple XBMC libraries, doing so is highly recommended as it:
*saves storage space by having thumbnails and fanart in just one network shared location
*saves time by not having to re-download the images separately for each XBMC device
 
The Thumbnail folder in XBMC contains both [[thumbnails]] and [[fanart]]. If you have imported from pre-existing media libraries then you can use your old thumbnail folder to save time on re-downloading images, but only if you did not use local file paths and only had network shares on your exported library. Otherwise you will have to update your library to re-download thumbnails and fanart.
 
 
{| class="infobox"
| add to advancedsettings.xml:
|-
|
<pre>
<pathsubstitution>
  <substitute>
    <from>special://masterprofile/Thumbnails/</from>
    <to>REPLACE_THIS_TEXT</to>
  </substitute>
</pathsubstitution>
</pre>
|}
#Share your existing Thumbnail folder or a new folder via NFS, SMB, or AFP. It's easiest to do this from the same computer/device as your MySQL server.
#* '''Windows XP:''' <code>Documents and Settings\<your_user_name>\Application Data\XBMC\userdata\Thumbnails\</code>
#* '''Vista/Windows 7:''' <code>Users\<your_user_name>\AppData\Roaming\XBMC\userdata\Thumbnails\</code>
#* '''Mac OS X:''' <code>/Users/<your_user_name>/Library/Application Support/XBMC/userdata/Thumbnails/</code>
#* '''iOS:''' <code>/private/var/mobile/Library/Preferences/XBMC/userdata/Thumbnails/</code>
#* '''Linux:''' <code>$HOME/.xbmc/userdata/Thumbnails/</code>
#Copy the text from the right hand box and add it to your '''advancedsettings.xml''' file, but make sure you add the text before the <code></advancedsettings></code> tag at the end.
#Note/copy the network path of your shared Thumbnails folder and use that to replace '''REPLACE_THIS_TEXT'''.
for example an SMB share holding your thumbs use 'smb://NAS/share/videos/Thumbs/'
#Make sure all XBMC devices that are being synced have this addition to their ''advancedsettings.xml'' file.
 
== Upgrading XBMC from v10 to v11 ==
{{notice|Right now Eden builds are pre-release builds that may contain bugs, including some funky stuff with MySQL. If you want to play it super safe it's best to upgrade by: export your library, delete the old MySQL databases, upgrade to pre-Eden, then reimport the library. You will still need to set up MySQL to let XBMC create databases, as noted below. }}
When upgrading from XBMC v10 (Dharma) to XBMC v11 (Eden) you may need to make changes to your MySQL server. The user made for the MySQL DB ("XBMC" in most guides) will need access to create new databases. If the user already has that access then you don't need to do anything.
 
 
The latest pre-Eden builds will make a copy of the current DB and upgrade the copy. That way if anything goes wrong in the upgrading you still have an original untouched copy of your DB.
 
 
Some instructions, such as the Lifehacker guide and this how-to, are already set up this way:
* <code>GRANT ALL ON *.* TO 'xbmc';</code>
 
 
If all you use your MySQL server for is XBMC, then that's all you need to do. Some users like to limit the access the "XBMC" user has to MySQL and prefer to use this instead (Make note of the <code>`</code> vs <code>'</code> ):
* <code>GRANT ALL PRIVILEGES ON `xbmc_%`.* TO 'xbmc'@'%';</code>


;{{big|MySQL Protocol & MariaDB}}
<section begin="MariaDB" />When setting up shared Library databases either MySQL or MariaDB can be used as they both use the same MySQL protocol. Since many Linux distributions have dropped including MySQL and now instead now ship MariaDB, it is being more common to use MariaDB for shared Library databases.<section end="MariaDB" />


Either MySQL command will work in case your server is not already set up to let XBMC make new databases.


== Using profiles with MySQL libraries ==
{{next|[[MySQL/Setting up MySQL|Setting up MySQL]]}}
{{editor note|Note that you can use profiles to switch between a local library and a MySQL library, or even two different MySQL libraries. Also note "roaming profiles" concept for portable device users (including laptops!) to prevent XBMC from freezing up (for example see: [[forum:92807]])}}


== See also ==
{{Updated|16}}
*[[MythTV:Category:MySQL]]


[[Category:How-to]]
[[Category:How-to]]
[[Category:File Sharing]]
[[Category:File sharing]]
[[Category:Guides]]
[[Category:Advanced topics]]

Latest revision as of 04:51, 23 January 2022

Share libraries w/MySQL, guide:

  1. Introduction
  2. Setting up MySQL
  3. Setting up Kodi
Network.png
Introduction

If you have more than one Kodi device on your local network then you might want to synchronize them by sharing the Kodi library databases via the MySQL protocol. Using shared library databases allows you to store information for either your video or music library in a central database, so that multiple devices can access the same information at the same time.

This gives you the ability to do things like:

  • Share watched and unwatched status for your media on all devices
  • Stop watching a movie or TV show in one room then finish watching it in another room automatically
  • Only one library to maintain for all devices


MySQL Protocol & MariaDB

When setting up shared Library databases either MySQL or MariaDB can be used as they both use the same MySQL protocol. Since many Linux distributions have dropped including MySQL and now instead now ship MariaDB, it is being more common to use MariaDB for shared Library databases.


Next step: Setting up MySQL