MySQL: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
>Patrickd
(Added "How to sync playlists")
Line 131: Line 131:




 
===Symlink alternative===
If your operating system supports symlinks, you can instead use a symlink which is much faster and easier, and does not require editing the advancedsettings.xml. Here's how:
{{Hidden
 
| headerstyle = background:#ccccff; text-align:left;
| header = If your operating system supports symlinks, you can instead use a symlink which is much faster and easier, and does not require editing the advancedsettings.xml. Here's how:
| content =
Assuming you have all of the share permissions correct, you can just '''REPLACE''' your thumbnails folder on all of the machines except the '''HOST''' machine with a symlink.  
Assuming you have all of the share permissions correct, you can just '''REPLACE''' your thumbnails folder on all of the machines except the '''HOST''' machine with a symlink.  


Line 148: Line 150:
No further settings need to be adjusted, every machine that you do this on will essentially think it is using it's own thumbnails directory, but will in fact be using the HOST machines thumbnail directory. You do not HAVE to use the actual thumbnail directory of an existing XBMC installation as in the example code above. You could, for instance, use a neutral share and then create the symlink on the thumbnails directory for ALL of your machines.
No further settings need to be adjusted, every machine that you do this on will essentially think it is using it's own thumbnails directory, but will in fact be using the HOST machines thumbnail directory. You do not HAVE to use the actual thumbnail directory of an existing XBMC installation as in the example code above. You could, for instance, use a neutral share and then create the symlink on the thumbnails directory for ALL of your machines.


If you were previously using the path substitution method, make sure you remove the path substitution from all machines that you use the symlink on.  
If you were previously using the path substitution method, make sure you remove the path substitution from all machines that you use the symlink on.
}}


== Syncing playlists ==
== Syncing playlists ==

Revision as of 07:17, 7 January 2012

Template:XBMC wiki toc 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:

  • 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
  • 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.png INCOMPLETE:
This page or section is incomplete. Please add information or correct uncertain data which is marked with a ?

MySQL can be installed on just about every major OS:

  1. Install MySQL server
  2. Create a password when asked
  3. Give the database access to your network:
    • Linux: Comment out the following line in the MySQL configuration file (/etc/mysql/my.cnf)
    1. from: bind-address = 127.0.0.1
    2. to  : #bind-address = 127.0.0.1
    • Mac OS X:
    • Windows: Select that you want the database to have network access when prompted during installation.
  4. Get into the MySQL command line interface:
    • Linux: $mysql -u root -p
    • Mac OS X:
    • Windows: Open the "MySQL Command Line Client" from the MySQL start menu
  5. Enter the following commands:
    1. Type in: CREATE USER 'xbmc' IDENTIFIED BY 'xbmc'; and press return
    2. Type in: GRANT ALL ON *.* TO 'xbmc'; and press return
    Editor note: Note these "speed up" commands here -> http://xbmcstuff.bossanova808.net/2011/03/summary-of-xbmc-mysql-database.html?m=1
  6. Close out the command line tool

On a NAS

MySQL can also be installed on some network-attached storage (NAS) device devices. See one of the following guides for more info:

Setting up XBMC

advancedsettings.xml:
<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>
  1. 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 Editor note: <-- need help expanding here in addition to sharing the files on the network.
    1. Export the Video Library by doing the following:
      1. Go to System/Settings -> Video -> Library and select Export library
      2. Select Single file
    2. Export the Music Library by doing the following:
      1. Go to System/Settings -> Music -> Library and select Export library
      2. Select Single file
  2. 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
    4. Save the file as advancedsettings.xml
  3. Copy this advancedsettings.xml file you just created to the userdata folder of every XBMC install you want to sync with:
    • Windows XP: Documents and Settings\<your_user_name>\Application Data\XBMC\userdata\advancedsettings.xml
    • Vista/Windows 7: Users\<your_user_name>\AppData\Roaming\XBMC\userdata\advancedsettings.xml
    • Mac OS X: /Users/<your_user_name>/Library/Application Support/XBMC/userdata/advancedsettings.xml
    • iOS: /private/var/mobile/Library/Preferences/XBMC/userdata/advancedsettings.xml
    • Linux: $HOME/.xbmc/userdata/advancedsettings.xml
  4. 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)
    1. Import the Video Library by doing the following:
      1. Go to System/Settings -> Video -> Library and select Import library
      2. Select the file you saved from the first step when you exported your video library
    2. Import the Music Library by doing the following:
      1. Go to System/Settings -> Music -> Library and select Import library
      2. Select the file you saved from the first step when you exported your music library
  5. 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.


add to advancedsettings.xml:
<pathsubstitution>
  <substitute>
    <from>special://masterprofile/Thumbnails/</from>
    <to>YOUR_NETWORK_SHARE_FOR_THUMBNAILS</to>
  </substitute>
</pathsubstitution>
  1. 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: Documents and Settings\<your_user_name>\Application Data\XBMC\userdata\Thumbnails\
    • Vista/Windows 7: Users\<your_user_name>\AppData\Roaming\XBMC\userdata\Thumbnails\
    • Mac OS X: /Users/<your_user_name>/Library/Application Support/XBMC/userdata/Thumbnails/
    • iOS: /private/var/mobile/Library/Preferences/XBMC/userdata/Thumbnails/
    • Linux: $HOME/.xbmc/userdata/Thumbnails/
  2. 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 </advancedsettings> tag at the end.
  3. Note/copy the network path of your shared Thumbnails folder and use that to replace YOUR_NETWORK_SHARE_FOR_THUMBNAILS, for example an SMB share holding your thumbs use 'smb://NAS/share/videos/Thumbs/'
  4. Make sure all XBMC devices that are being synced have this addition to their advancedsettings.xml file.


Symlink alternative

Syncing playlists

While syncing playlist is not required for sharing multiple XBMC libraries, doing so is highly recommended as it saves time by not creating and maintaining playlists on every XBMC devices.

The Playlist folder in XBMC contains music, video and mixedplaylists. If you have imported from pre-existing media libraries then you can use your old playlist folder to save time on recreating the various playlists. If your playlists include local file paths, you will need to edit them to use network shares instead.

add to advancedsettings.xml:
<pathsubstitution>
  <substitute>
    <from>special://masterprofile/playlists/</from>
    <to>YOUR_NETWORK_SHARE_FOR_PLAYLISTS</to>
  </substitute>
</pathsubstitution>
  1. Share your existing playlists 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: Documents and Settings\<your_user_name>\Application Data\XBMC\userdata\playlists\
    • Vista/Windows 7: Users\<your_user_name>\AppData\Roaming\XBMC\userdata\playlists\
    • Mac OS X: /Users/<your_user_name>/Library/Application Support/XBMC/userdata/playlists/
    • iOS: /private/var/mobile/Library/Preferences/XBMC/userdata/playlists/
    • Linux: $HOME/.xbmc/userdata/playlists/
  2. 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 </advancedsettings> tag at the end.
  3. Note/copy the network path of your shared playlists folder and use that to replace YOUR_NETWORK_SHARE_FOR_PLAYLISTS, for example an SMB share holding your playlists use 'smb://NAS/share/videos/Playlists/'
  4. Make sure all XBMC devices that are being synced have this addition to their advancedsettings.xml file.


If your operating system supports symlinks, you can instead use a symlink which is much faster and easier, and does not require editing the advancedsettings.xml. Here's how:

Assuming you have all of the share permissions correct, you can just REPLACE your thumbnails folder on all of the machines except the HOST machine with a symlink.

Here is an example for XBMC users on Windows 7:

Open an elevated command prompt (run as administrator) and then type in:

CD C:\Users\User_name\AppData\Roaming\XBMC\userdata\

mklink /D playlists \\HTPC\Users\User_name\AppData\Roaming\XBMC\userdata\playlists

Obviously, you need to adjust the paths for YOUR specific machine(s) or this won't work. Make sure you can reach the shared playlist directory through Explorer on each machine. If you can't, you have a permissions problem.

No further settings need to be adjusted, every machine that you do this on will essentially think it is using it's own playlist directory, but will in fact be using the HOST machines playlist directory. You do not HAVE to use the actual playlist directory of an existing XBMC installation as in the example code above. You could, for instance, use a neutral share and then create the symlink on the playlist directory for ALL of your machines.

If you were previously using the path substitution method, make sure you remove the path substitution from all machines that you use the symlink on.

Syncing other parts of XBMC

See: /complete sync tips

Upgrading XBMC from v10 to v11

Emblem-important-yellow.png 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. BACKUP YOUR DATABASE JUST IN CASE. Also EXPORT your library from your current version before beginning the upgrade process or you may find yourself starting your library from scratch.


Some instructions, such as the Lifehacker guide and this how-to, are already set up this way:

  • GRANT ALL ON *.* TO 'xbmc';


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 ` vs ' ):

  • GRANT ALL PRIVILEGES ON `xbmc_%`.* TO 'xbmc'@'%';


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

Alternatively, you could use your root account, or create a new account just for the upgrade process that has the permissions to modify/create databases. After upgrading, you could drop the new user and switch back to your default 'xbmc' account, though you need to be sure you grant that account permissions on the new database(s) that are created. If you have installed MySQL for the sole purpose of configuring a shared XBMC database, then this probably is not something you want to worry about.


If your upgrade fails with database errors, you should edit your advancedsettings.xml and remove the lines <name>xbmc_video</name> and <name>xbmc_music</name> for the upgrade process. You only need to do this on the first machine you upgrade with, the other machines will instead need to be edited later. Once the upgrade is finished and you confirm on the first machine that the database is functioning and populated properly, shut down XBMC. You can now replace the tags you removed before the upgrade, however you need to use the names of the NEW databases. As of Eden Beta 1, those names are myvideos58 and mymusic18. You will also need to change the name on ALL of your other machines accessing the databases. Your new name tags (again, as of Eden Beta 1) would then appear as:

<name>myvideos58</name> and <name>mymusic18</name>

Also note that you can simply remove the name lines from advancedsettings.xml on ALL of your machines and each machine will be able to access the same database without a problem as long as you are running the same version of XBMC on each machine (don't try running Eden Beta 1 on one machine and Dharma 10.1 on another). If you use different versions of XBMC you are going to have problems with using a database to sync all of your systems whether you use the <name> tags or not.

Using profiles with MySQL libraries

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