MySQL/Setting up MySQL

You'll need to choose which of your computers, Kodi 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 Kodi device that is hosting most or all of your videos and music to also be the MySQL server, but this is not required.

MySQL can be installed on just about every major OS:

=Ubuntu Linux= Ubuntu Linux:
 * 1)  (see also: https://help.ubuntu.com/10.04/serverguide/C/mysql.html )
 * 2) Create a password when asked
 * 3) To configure MySQL to listen for connections from network hosts, edit /etc/mysql/my.cnf and change the bind-address directive to the server's IP address:
 * 4) from:
 * to:
 * 1) *Note: Replace 192.168.0.5 with the appropriate address.
 * 2) *Note: To allow local and remote access try comment out bind-address using a hash(#) or use
 * 3) Restart your MySQL server.
 * 4) Get into the MySQL command line utility:
 * 5) Enter the following commands:
 * 6) Type in:  and press return
 * 7) Type in:  and press return
 * 8) Close out the command line tool with

=Arch Linux= Arch Linux:
 * Please note: Arch, along with many other distributions, has migrated to the faster and more open MariaDB. It is a drop in replacement to MySQL and, thus, Kodi will require no modifications to work with it.
 * 1) Install MariaDB:
 * 2) Start the service:
 * 3) To have it automatically launch at startup:
 * 4) Create a password:  This will also clean up the demo database.
 * 5) Get into the MariaDB command line utility:
 * 6) Enter the following commands:
 * 7) Type in:  and press return
 * 8) Type in:  and press return
 * 9) Close out the command line tool with

=RedHat based Linux= RedHat based Linux (RHEL, CentOS, Fedora):
 * 1) Create a password when asked
 * 2) To configure MySQL to listen for connections only from network hosts, edit /etc/mysql/my.cnf and add the bind-address directive to the server's IP address:
 * 1) To configure MySQL to listen for connections only from network hosts, edit /etc/mysql/my.cnf and add the bind-address directive to the server's IP address:


 * 1) *Note: Replace 192.168.0.5 with the appropriate address.
 * 2) *Note: Alternatively you can leave this file as is to allow local and remote access.
 * 3) Restart your MySQL server.
 * 4) *Recommended - Set your MySQL root password with
 * 5) Get into the MySQL command line utility:
 * 6) *Enter your MySQL root password as set above, or just press enter if you didn't set one to log in with a blank password
 * 7) Enter the following commands:
 * 8) Type in:  and press return
 * 9) Type in:  and press return
 * 10) Close out the command line tool with

=Mac OS X= Mac OS X:
 * 1) Download a copy of MySQL server from http://dev.mysql.com/downloads/mysql/
 * 2) In Mac OS X, go to System Preferences -> MySQL, and click on “Start MySQL Server”. You’ll also want to tick to enable the “Automatically … on Startup” option.
 * 3) Now to set up the "kodi" user in MySQL and give it access. Launch Terminal.app on your Mac and issue the following commands, one line at a time:
 * 4) Remain in Terminal.app. Now you'll be giving other computers on your network access to MySQL. Enter the next set of commands, one line at a time:
 * ''The command line will ask for your Mac OS X user password. Enter it and press return. No text will show when you type your password in, this is normal.
 * This opens a file in a command line text editor
 * 1) Scroll down to the [mysqld] section and add or edit the following line so that it appears as:
 * 2) Save and exit from the command line text editor
 * 3) Reboot the Mac, or restart the MySQL service from the System Preferences pane you installed earlier
 * ''The command line will ask for your Mac OS X user password. Enter it and press return. No text will show when you type your password in, this is normal.
 * This opens a file in a command line text editor
 * 1) Scroll down to the [mysqld] section and add or edit the following line so that it appears as:
 * 2) Save and exit from the command line text editor
 * 3) Reboot the Mac, or restart the MySQL service from the System Preferences pane you installed earlier
 * 1) Scroll down to the [mysqld] section and add or edit the following line so that it appears as:
 * 2) Save and exit from the command line text editor
 * 3) Reboot the Mac, or restart the MySQL service from the System Preferences pane you installed earlier
 * 1) Reboot the Mac, or restart the MySQL service from the System Preferences pane you installed earlier


 * Alternative guide for Mac OS X: http://forum.kodi.tv/showthread.php?tid=151631

=Windows=

Installing MySQL on Windows
If you have chocolatey installed run choco install mysql
 * or


 * 1) Download a copy of MySQL server from http://dev.mysql.com/downloads/mysql/ (Grab version 5.5.42, there are issues with newer versions)
 * 2) Select Server only
 * 3) Create a password when asked
 * 4) Select that you want the database to have network access when prompted during installation.

If you're using a firewall such as the one that's built into Windows, you will need to follow the steps below for the version of windows you installed Kodi on.

Windows 7/8/8.1 Built-in Firewall

 * Run the following command in powershell or execute all the steps below.

New-NetFirewallRule -DisplayName "Allow inbound TCP Port 3306 for MySQL" -Direction inbound –LocalPort 3306 -Protocol TCP -Action Allow
 * Go to control panel and open Windows Firewall
 * Click on Advanced Settings
 * Click on Inbound Rules, then New Rule
 * For the Rule Type, choose Port and hit Next
 * For Protocol and Ports, select TCP protocol and type in 3306 for the Specific local ports and hit Next
 * For Action, leave it at default which is Allow the connection and hit Next
 * For Profile, you can leave it as default (everything checked by default) and hit Next
 * For Name, set it to MySQL or any name that you will know what it is and click Finished

Windows XP Built-in Firewall

 * Open Control Panel and Set to 'Classic View'
 * Double Click on Windows Firewall
 * Click on tab that says Exceptions
 * Click on Add Port
 * Name it MySQL or any other name
 * Set the port number to 3306
 * Choose TCP and click OK

Setup users in MySQL for Kodi clients

 * 1) Open the "MySQL Command Line Client" from the MySQL start menu
 * 2) Enter the following commands:
 * 3) Type in:  and press return
 * 4) Type in:  and press return
 * 5) Close out the command line tool

If this occurs to you, try amending Step 2 above to read  where xxx.xxx.xxx is the first three quadrants of your home network's IP address (192.168.1 for example) and % as the last quadrant to allow addresses on the same subnet to connect.

=Other NAS= MySQL can also be installed on some network-attached storage (NAS) device devices. Here are some guides for various NAS devices that can have a MySQL server installed:


 * Devices running Arch Linux ARM (such as the PogoPlug, Dockstar, etc) can use the Arch Linux instructions on this page.
 * Synology NAS as MySQL server for XBMC and http://youtu.be/3PmmDtK65ks
 * http://www.robvanhamersveld.nl/2013/02/05/share-your-xbmc-12-0-library-on-a-synology-ds-or-other-nas/ Synology DS with MySQL guide based on Frodo
 * http://forum.kodi.tv/showthread.php?tid=172548 - unRAID

=FreeNAS and freeBSD=

About FreeNAS
http://www.freenas.org/

FreeNAS is a FreeBSD based NAS system that can be run on almost any hardware - it uses ZFS for disk and file management. It is used at home and in enterprise businesses. 99% of tasks can be done via the web interface.

Example below is based on FreeNAS 9.1.1 on 12/12/13, and assumes you have already configured your nas with drives, datasets etc

Make a jail
create a Jail via the FreeNAS webui - if unsure see here http://doc.freenas.org/index.php/Adding_Jails

make a note of the jail IP address shown - you will need this to put in the advancedsettings.xml file on the Kodi machine later

Prepare the jail

 * ssh into FreeNAS
 * If you have a windows PC use putty (http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)
 * (easiest) click the "shell" button in the left of the FreeNAS webui

type the following commands



Take note of the JID of the jail you created, use it in the command below and replace n with the number of the jail you just created



Install mysql
You are now inside your jail




 * (nano is a text editor you will need shortly)
 * (nano is a text editor you will need shortly)

We now need to enable mysql in rc.conf



insert the line below into the rc.conf file



save the file and exit (see bottom of nano edit page for keystrokes info)



Optional step below - this is an automated script that will secure you mysql instance - it will prompt you for answers to questions. Its up to you if you do this.



Configure mysql ready for Kodi to use
type in



You are now in mysql administration



=Restricting MySQL access rights= Optional: If you only use the MySQL server for Kodi and that server has non-critical data on it, then this probably not necessary. For a more secure MySQL installation use these 2 commands to grant permission only to databases Kodi uses. This is useful if you plan on using your MySQL server for more than just Kodi, or if you're worried about your internal network being exposed and wanting to lock things down more, etc.