MySQL/Setting up MySQL: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
 
(104 intermediate revisions by 25 users not shown)
Line 1: Line 1:
{{Frodo updated}}{{:HOW-TO:Sync multiple libraries/Contents}}
{{:MySQL/Contents}}
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.
{{mininav| [[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.
{{-}}
{{-}}


<big>{{notice|Users are reporting issues with '''MySQL 5.6'''. Use '''MySQL 5.5''' instead.}}</big>
{{redv|'''Please Note:'''| Do not manually create the MySQL/MariaDB databases on your database server. Set up the MySQL/MariaDB server, and Kodi will create the specific databases for you.}}
MySQL can be installed on just about every major OS:
{{redv|'''Also:'''| Some versions of MySQL set their passwords to expire by default, '''even the root password'''!  If the password expires, Kodi cannot access the database and the TV Series and Movies libraries will disappear.<br />
To avoid this and/or fix it after it happens, make sure the account's password does not expire. (See: https://dev.mysql.com/doc/refman/5.7/en/password-management.html )}}
 
MySQL/MariaDB can be installed on just about every major OS and NAS:
 
{{redv|'''Important:'''| Please use only supported versions of the MySQL or MariaDB server. As of January 2019, this is MySQL in at least version 5.7 or MariaDB in at least version 5.5, but version 10.3+ is recommended.}}


=Ubuntu Linux=
=Ubuntu Linux=
'''Ubuntu Linux:'''
'''Ubuntu Linux:'''
#<code>$sudo apt-get install mysql-server</code> ''(see also: https://help.ubuntu.com/10.04/serverguide/C/mysql.html )''
#<code>$sudo apt-get install mysql-server</code> ''(see also: https://help.ubuntu.com/18.04/serverguide/mysql.html )''
#Create a password when asked
#Create a password when asked
#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:
#To configure MySQL to listen for connections from network hosts, edit ''/etc/mysql/mysql.conf.d/mysqld.cnf'' and change the bind-address directive to the server's IP address:
##from: <code>bind-address = 127.0.0.1</code>  
##from: <code>bind-address = 127.0.0.1</code>  
##to: <code>bind-address = 192.168.0.5</code>
##to: <code>bind-address = 192.168.0.5</code>
#*Note: Replace 192.168.0.5 with the appropriate address.
#*Note: Replace 192.168.0.5 with the appropriate address.
#*Note: To allow local and remote access try comment out bind-address using a hash(#) or use <code>bind-address = 0.0.0.0</code>
#*Note: To allow both local and remote access (i.e. from both the MySQL host to itself and also from other clients), either comment out the bind-address using a hash (#) to disable it, or use <code>bind-address = 0.0.0.0</code> to open it completely.
#Restart your MySQL server. <code>$sudo restart mysql</code>
#When using MySQL8 or higher (Ubuntu 20.04 or later), add the following line at the end of ''/etc/mysql/mysql.conf.d/mysqld.cnf'':
#Get into the MySQL command line utility: <code>$mysql -u root -p</code>
##<code>default_authentication_plugin=mysql_native_password</code>
##*Note: When using MariaDB this is the default, so you don't need to set it separately
#Restart your MySQL server. <code>sudo service mysql restart</code>
#Get into the MySQL command line utility: <code>mysql -u root -p</code>
#Enter the following commands:
#Enter the following commands:
##Type in: <code>CREATE USER 'xbmc' IDENTIFIED BY 'xbmc';</code> and press return
##Type in: <code>CREATE USER 'kodi' IDENTIFIED BY 'kodi';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'xbmc';</code> and press return
##*Note: When using MySQL8 or higher, there are additional password requirements and new authentication methods. Using the following command should avoid errors. Type in: <code>CREATE USER 'kodi' IDENTIFIED WITH mysql_native_password BY 'kodi123#';</code> and press return
##*Note: If the above command throws the error <code>ERROR 1064 (42000): You have an error in your SQL syntax;</code> (could happen if using MariaDB 10.5) try this one: <code>CREATE USER 'kodi' IDENTIFIED VIA mysql_native_password USING PASSWORD('kodi123#');</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'kodi';</code> and press return
##Type in: <code>flush privileges;</code> and press return
#Close out the command line tool with <code>\q</code>
#Close out the command line tool with <code>\q</code>
=Debian Linux=
'''Debian Linux:'''
#Login as root with <code>$ su -</code>
#<code># apt-get install mariadb-server</code>
#To configure MySQL/MariaDB to listen for connections from network hosts, edit ''/etc/mysql/mariadb.conf.d/50-server.cnf'' and change the bind-address directive to the server's IP address:
##from: <code>bind-address = 127.0.0.1</code>
##to: <code>bind-address = 192.168.0.5</code>
#*Note: Replace 192.168.0.5 with the appropriate address.
#*Note: To allow both local and remote access (i.e. from both the MySQL/MariaDB host to itself and also from other clients), either comment out the bind-address using a hash (#) to disable it, or use <code>bind-address = 0.0.0.0</code> to open it completely.
#Restart your MySQL/MariaDB server. <code># systemctl restart mariadb</code>
#Get into the MySQL command line utility: <code># mysql</code>
#Enter the following commands:
##Type in: <code>CREATE USER 'kodi' IDENTIFIED VIA mysql_native_password USING PASSWORD('kodi123#');</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'kodi';</code> and press return
##Type in: <code>flush privileges;</code> and press return
#Close out the command line tool with <code>exit</code> or <code>\q</code>
#Logout as root with <code># exit</code>


=Arch Linux=
=Arch Linux=
'''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, XBMC will require no modifications to work with it.
*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.
#Install MariaDB: <code>$ sudo pacman -S mariadb</code>
#Install MariaDB: <code>$ sudo pacman -S mariadb</code>
#Start the service: <code>$ sudo systemctl start mysqld</code>
#Start the service: <code>$ sudo systemctl start mysqld</code>
Line 31: Line 61:
#Get into the MariaDB command line utility: <code>$ mysql -u root -p</code>
#Get into the MariaDB command line utility: <code>$ mysql -u root -p</code>
#Enter the following commands:
#Enter the following commands:
##Type in: <code>CREATE USER 'xbmc' IDENTIFIED BY 'xbmc';</code> and press return
##Type in: <code>CREATE USER 'kodi' IDENTIFIED BY 'kodi';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'xbmc';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'kodi';</code> and press return
##Type in: <code>flush privileges;</code> and press return
#Close out the command line tool with <code>\q</code>
#Close out the command line tool with <code>\q</code>


Line 47: Line 78:
#*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
#*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
#Enter the following commands:
#Enter the following commands:
##Type in: <code>CREATE USER 'xbmc' IDENTIFIED BY 'xbmc';</code> and press return
##Type in: <code>CREATE USER 'kodi' IDENTIFIED BY 'kodi';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'xbmc';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'kodi';</code> and press return
##Type in: <code>flush privileges;</code> and press return
#Close out the command line tool with <code>\q</code>
 
=RaspberryPi Raspbian=
 
'''RaspberryPi Raspbian:'''
#<code>$sudo apt-get update && sudo apt-get dist-upgrade</code> to ensure that you have the very latest iteration of Raspbian. ''(September 2017 as of writing this)''
#<code>$sudo apt-get install mysql-server</code> to install ''MYSQL Server''.
#To configure MySQL to listen for connections from network hosts, <code>$sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf</code> and change the bind-address directive to the server's IP address:
##from: <code>bind-address = 127.0.0.1</code>
##to: <code>bind-address = 192.168.0.5</code>
#*Note: Replace 192.168.0.5 with the appropriate address.
#*Note: To allow both local and remote access (i.e. from both the MySQL host to itself and also from other clients), either comment out the bind-address using a hash (#) to disable it, or use <code>bind-address = 0.0.0.0</code> to open it completely.
#Restart your MySQL server: <code>sudo service mysql restart</code>
#Get into the MySQL command line utility: <code>sudo mysql</code>
#Enter the following commands:
##Type in: <code>CREATE USER 'kodi' IDENTIFIED BY 'kodi';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'kodi';</code> and press return
##Type in: <code>flush privileges;</code> and press return
#Close out the command line tool with <code>\q</code>
#Close out the command line tool with <code>\q</code>


Line 55: Line 105:
#Download a copy of MySQL server from http://dev.mysql.com/downloads/mysql/
#Download a copy of MySQL server from http://dev.mysql.com/downloads/mysql/
#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.
#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.
#Now to set up the "xbmc" user in MySQL and give it access. Launch Terminal.app on your Mac and issue the following commands, one line at a time:
#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:
##<code>sudo /usr/local/mysql/bin/mysql</code>
##<code>sudo /usr/local/mysql/bin/mysql</code>
##<code>CREATE USER 'xbmc' IDENTIFIED BY 'xbmc';</code>
##<code>CREATE USER 'kodi' IDENTIFIED BY 'kodi';</code>
##<code>GRANT ALL ON *.* TO 'xbmc';</code>
##<code>GRANT ALL ON *.* TO 'kodi';</code>
##<code>exit</code>
##<code>exit</code>
#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:
#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:
Line 73: Line 123:




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


=Windows=
=Windows=
'''Windows:'''
== Installing MySQL on Windows ==
#Download a copy of MySQL server from http://dev.mysql.com/downloads/mysql/
If you have chocolatey installed run '''choco install mysql'''
#Select ''Standard configuration''
:'''or'''
#Download a copy of MySQL server from https://dev.mysql.com/downloads/windows/installer/8.0.html
#Select ''Archives'' when you want the last stable main version 5.7.36 instead of version 8.0.x.
#Create a password when asked
#Create a password when asked
#Select that you want the database to have network access when prompted during installation.
#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.
:::<syntaxhighlight lang="text" enclose="div">
New-NetFirewallRule -DisplayName "Allow inbound TCP Port 3306 for MySQL" -Direction inbound –LocalPort 3306 -Protocol TCP -Action Allow
</syntaxhighlight>
:#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
== Setup users in MySQL for Kodi clients ==
#Open the "MySQL Command Line Client" from the MySQL start menu
#Open the "MySQL Command Line Client" from the MySQL start menu
#Enter the following commands:
#Enter the following commands:
##Type in: <code>CREATE USER 'xbmc' IDENTIFIED BY 'xbmc';</code> and press return
##Type in: <code>CREATE USER 'kodi' IDENTIFIED BY 'kodi';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'xbmc';</code> and press return
##Type in: <code>GRANT ALL ON *.* TO 'kodi';</code> and press return
##Type in: <code>flush privileges;</code> and press return  
#Close out the command line tool
#Close out the command line tool
#In '''Windows 7''', you may need to make an exception in the "Windows Firewall"
##Go to control panel and open windows firewall
##Click on advanced settings
##Click on Inbound Rules, then new rule
##Chose the port option, click next
##Then type in the port number you set mysql to use(Default is 3306)
##Make sure Allow the connection is checked then click next
##Name it MYSQL Inbound(or whatever you want) then click finish
##Use these same steps to set up the Outbound exception then name it MYSQL Outbound(or whatever you want) then you're finished.
#:You may or may not have to set up both in and outbound, someone with more knowledge please edit this if you know.
#In '''Windows XP''', you may need to make an exception in the "Windows Firewall"
##Open Control Panel and Set to 'Classic View'
##Double Click on Windows Firewall
##Click on Exception-->Add Port
##Name It MySQL XBMC or whatever you want
##Then type in the port number you set mysql to use(Default is 3306)
#:{{Note|You must do this twice:Once for UDP and once for TCP}}


{{Note|If XBMC is unable to connect to the MySQL server, returning an error code [1130]:}}<br/>
{{Note|If Kodi is unable to connect to the MySQL server, returning an error code [1130]:}}<br/>
If this occurs to you, try amending Step 2 above to read <code>GRANT ALL ON *.* TO 'xbmc'@'xxx.xxx.xxx.%';</code> 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.
If this occurs to you, try amending Step 2 above to read <code>GRANT ALL ON *.* TO 'kodi'@'xxx.xxx.xxx.%';</code> 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.


=NAS=
=Other NAS=
MySQL can also be installed on some [[w:network-attached storage|network-attached storage (NAS)]] device devices. Here are some guides for various NAS devices that can have a MySQL server installed:
MySQL can also be installed on some [[w:network-attached storage|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): [[HOW-TO:Sync multiple libraries/Setting up MySQL/ALARM]]
*Devices running Arch Linux ARM (such as the PogoPlug, Dockstar, etc) can use the [[Setting_up_MySQL|Arch Linux instructions]] on this page.
*[http://ozymandyaz.blogspot.com/2011/08/configure-synology-nas-as-mysql-server.html Synology NAS as MySQL server for XBMC]
*[https://web.archive.org/web/20160329053954/http://quixventure.com/2011/12/configure-a-synology-nas-as-mysql-server-for-xbmc/ Synology NAS as MySQL server for XBMC] and http://youtu.be/3PmmDtK65ks
*http://quixventure.com/2011/12/configure-a-synology-nas-as-mysql-server-for-xbmc/ New link for Synology NAS as MySQL server for XBMC
*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://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
After setting up a database server on you NAS, you should create a Kodi user with full administrative privileges. The user should be able to log in from your Kodi devices, so make sure you give the user login access from external machines.
You do not need to create a database as Kodi will create the required databases itself.
{{redv|'''Warning:'''| As you are giving the Kodi user full administrative privileges and external machine access it is recommended that you review your database security. It is highly recommenced that you block internet access to your database using an appropriate firewall. }}
=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
== How to ==
=== 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
*<code>jls</code>
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
*<code>jexec n csh</code>
=== Install mysql ===
You are now inside your jail
*<code>pkg install mysql55-server</code>
*<code>pkg install nano</code>
**(nano is a text editor you will need shortly)
We now need to enable mysql in rc.conf
*<code>nano /etc/rc.conf</code>
insert the line below into the rc.conf file
*<code>mysql_enable="YES"</code>
save the file and exit (see bottom of nano edit page for keystrokes info)
*<code>service mysql-server start</code>
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.
*<code>mysql_secure_installation</code>
=== Configure mysql ready for Kodi to use ===
type in
*<code>mysql -u root -p</code>
You are now in mysql administration
* <code>CREATE USER 'kodi' IDENTIFIED BY 'kodi';</code>
* <code>GRANT ALL ON *.* TO 'kodi';</code>
* <code>flush privileges;</code>
* <code>quit;</code>
=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.
'''Upto MySQL Server 5.7 Server:'''
#<code>GRANT ALL ON `MyVideos%`.* TO 'kodi'@'%' IDENTIFIED BY 'kodi';</code>
#<code>GRANT ALL ON `MyMusic%`.* TO 'kodi'@'%' IDENTIFIED BY 'kodi';</code>
'''As per MySQL 8.0 Server and upwards:'''
#<code>GRANT ALL PRIVILEGES ON `MyVideos%`.* TO `kodi`@`%`;</code>
#<code>GRANT ALL PRIVILEGES ON `MyMusic%`.* TO `kodi`@`%`;</code>
{{redv|'''Careful'''|The limited grants on this page don't give the kodi user permissions to create required TRIGGERs during install or upgrade. '''Kodi requires these TRIGGERs to function properly.''' <br />
Use the broader grant *.* statement that is explained on the previous tabs while creating or upgrading the tables. Only restrict rights afterwards, if you need to. <br>
Alternatively, figure out how to specifically give the account the right to create the require TRIGGERS - this varies between MySQL versions. }}
<headertabs />
<headertabs />


*If your library loads slowly with MySQL then you may wish to check out '''[[HOW-TO:Sync multiple libraries/Advanced notes#MySQL speed-up tweaks|these MySQL speed-up tweaks]]'''.
{{Next|[[MySQL/Setting up Kodi|Setting up Kodi]]}}
{{Divbox|green||'''Optional:''' For a more secure MySQL installation use these 2 commands to grant permission only to databases XBMC uses. This is useful if you plan on using your MySQL server for more than just XBMC, or if you're worried about your internal network being exposed and wanting to lock things down more, etc. If you only use the MySQL server for XBMC and that server has non-critical data on it, then this probably not necessary.
#<code>GRANT ALL ON `MyMusic%`.* TO 'xbmc'@'%' IDENTIFIED BY 'xbmc';</code>
#<code>GRANT ALL ON `MyVideos%`.* TO 'xbmc'@'%' IDENTIFIED BY 'xbmc';</code>
Note: these grants do not appear to give the xbmc user permissions to create required TRIGGERs.  So either figure out how to do an additional limited grant to create TRIGGERs or use the broader grant *.* statement above. }}
 


{{Next|[[HOW-TO:Share libraries using MySQL/Setting up XBMC|Setting up XBMC]]}}
{{Isengard updated}}

Latest revision as of 11:32, 5 January 2024

Share libraries w/MySQL, guide:

  1. Introduction
  2. Setting up MySQL
  3. Setting up Kodi
Home icon grey.png   ▶ 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.

Please Note: Do not manually create the MySQL/MariaDB databases on your database server. Set up the MySQL/MariaDB server, and Kodi will create the specific databases for you.
Also: Some versions of MySQL set their passwords to expire by default, even the root password! If the password expires, Kodi cannot access the database and the TV Series and Movies libraries will disappear.
To avoid this and/or fix it after it happens, make sure the account's password does not expire. (See: https://dev.mysql.com/doc/refman/5.7/en/password-management.html )


MySQL/MariaDB can be installed on just about every major OS and NAS:

Important: Please use only supported versions of the MySQL or MariaDB server. As of January 2019, this is MySQL in at least version 5.7 or MariaDB in at least version 5.5, but version 10.3+ is recommended.


[edit]

Ubuntu Linux:

  1. $sudo apt-get install mysql-server (see also: https://help.ubuntu.com/18.04/serverguide/mysql.html )
  2. Create a password when asked
  3. To configure MySQL to listen for connections from network hosts, edit /etc/mysql/mysql.conf.d/mysqld.cnf and change the bind-address directive to the server's IP address:
    1. from: bind-address = 127.0.0.1
    2. to: bind-address = 192.168.0.5
    • Note: Replace 192.168.0.5 with the appropriate address.
    • Note: To allow both local and remote access (i.e. from both the MySQL host to itself and also from other clients), either comment out the bind-address using a hash (#) to disable it, or use bind-address = 0.0.0.0 to open it completely.
  4. When using MySQL8 or higher (Ubuntu 20.04 or later), add the following line at the end of /etc/mysql/mysql.conf.d/mysqld.cnf:
    1. default_authentication_plugin=mysql_native_password
      • Note: When using MariaDB this is the default, so you don't need to set it separately
  5. Restart your MySQL server. sudo service mysql restart
  6. Get into the MySQL command line utility: mysql -u root -p
  7. Enter the following commands:
    1. Type in: CREATE USER 'kodi' IDENTIFIED BY 'kodi'; and press return
      • Note: When using MySQL8 or higher, there are additional password requirements and new authentication methods. Using the following command should avoid errors. Type in: CREATE USER 'kodi' IDENTIFIED WITH mysql_native_password BY 'kodi123#'; and press return
      • Note: If the above command throws the error ERROR 1064 (42000): You have an error in your SQL syntax; (could happen if using MariaDB 10.5) try this one: CREATE USER 'kodi' IDENTIFIED VIA mysql_native_password USING PASSWORD('kodi123#'); and press return
    2. Type in: GRANT ALL ON *.* TO 'kodi'; and press return
    3. Type in: flush privileges; and press return
  8. Close out the command line tool with \q
[edit]

Debian Linux:

  1. Login as root with $ su -
  2. # apt-get install mariadb-server
  3. To configure MySQL/MariaDB to listen for connections from network hosts, edit /etc/mysql/mariadb.conf.d/50-server.cnf and change the bind-address directive to the server's IP address:
    1. from: bind-address = 127.0.0.1
    2. to: bind-address = 192.168.0.5
    • Note: Replace 192.168.0.5 with the appropriate address.
    • Note: To allow both local and remote access (i.e. from both the MySQL/MariaDB host to itself and also from other clients), either comment out the bind-address using a hash (#) to disable it, or use bind-address = 0.0.0.0 to open it completely.
  4. Restart your MySQL/MariaDB server. # systemctl restart mariadb
  5. Get into the MySQL command line utility: # mysql
  6. Enter the following commands:
    1. Type in: CREATE USER 'kodi' IDENTIFIED VIA mysql_native_password USING PASSWORD('kodi123#'); and press return
    2. Type in: GRANT ALL ON *.* TO 'kodi'; and press return
    3. Type in: flush privileges; and press return
  7. Close out the command line tool with exit or \q
  8. Logout as root with # exit
[edit]

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: $ sudo pacman -S mariadb
  2. Start the service: $ sudo systemctl start mysqld
  3. To have it automatically launch at startup: $ sudo systemctl enable mysqld
  4. Create a password: $ /usr/bin/mysql_secure_installation This will also clean up the demo database.
  5. Get into the MariaDB command line utility: $ mysql -u root -p
  6. Enter the following commands:
    1. Type in: CREATE USER 'kodi' IDENTIFIED BY 'kodi'; and press return
    2. Type in: GRANT ALL ON *.* TO 'kodi'; and press return
    3. Type in: flush privileges; and press return
  7. Close out the command line tool with \q
[edit]

RedHat based Linux (RHEL, CentOS, Fedora):

  1. $sudo yum install mysql-server
  2. Create a password when asked
  3. 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:
    bind-address = 192.168.0.5
    • Note: Replace 192.168.0.5 with the appropriate address.
    • Note: Alternatively you can leave this file as is to allow local and remote access.
  4. Restart your MySQL server. $sudo /sbin/service mysqld restart
    • Recommended - Set your MySQL root password with /usr/bin/mysqladmin -u root password 'new-password'
  5. Get into the MySQL command line utility: $mysql -u root -p
    • 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
  6. Enter the following commands:
    1. Type in: CREATE USER 'kodi' IDENTIFIED BY 'kodi'; and press return
    2. Type in: GRANT ALL ON *.* TO 'kodi'; and press return
    3. Type in: flush privileges; and press return
  7. Close out the command line tool with \q
[edit]

RaspberryPi Raspbian:

  1. $sudo apt-get update && sudo apt-get dist-upgrade to ensure that you have the very latest iteration of Raspbian. (September 2017 as of writing this)
  2. $sudo apt-get install mysql-server to install MYSQL Server.
  3. To configure MySQL to listen for connections from network hosts, $sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf and change the bind-address directive to the server's IP address:
    1. from: bind-address = 127.0.0.1
    2. to: bind-address = 192.168.0.5
    • Note: Replace 192.168.0.5 with the appropriate address.
    • Note: To allow both local and remote access (i.e. from both the MySQL host to itself and also from other clients), either comment out the bind-address using a hash (#) to disable it, or use bind-address = 0.0.0.0 to open it completely.
  4. Restart your MySQL server: sudo service mysql restart
  5. Get into the MySQL command line utility: sudo mysql
  6. Enter the following commands:
    1. Type in: CREATE USER 'kodi' IDENTIFIED BY 'kodi'; and press return
    2. Type in: GRANT ALL ON *.* TO 'kodi'; and press return
    3. Type in: flush privileges; and press return
  7. Close out the command line tool with \q
[edit]

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:
    1. sudo /usr/local/mysql/bin/mysql
    2. CREATE USER 'kodi' IDENTIFIED BY 'kodi';
    3. GRANT ALL ON *.* TO 'kodi';
    4. exit
  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:
    1. cd /usr/local/mysql/support-files/
    2. sudo cp my-huge.cnf /etc/my.cnf
      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.
    3. cd /etc
    4. sudo nano my.cnf
      This opens a file in a command line text editor
    5. Scroll down to the [mysqld] section and add or edit the following line so that it appears as:
      bind-address = ***.***.***.***
    6. Save and exit from the command line text editor
  5. Reboot the Mac, or restart the MySQL service from the System Preferences pane you installed earlier


[edit]

Installing MySQL on Windows

If you have chocolatey installed run choco install mysql

or
  1. Download a copy of MySQL server from https://dev.mysql.com/downloads/windows/installer/8.0.html
  2. Select Archives when you want the last stable main version 5.7.36 instead of version 8.0.x.
  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
  1. Go to control panel and open Windows Firewall
  2. Click on Advanced Settings
  3. Click on Inbound Rules, then New Rule
  4. For the Rule Type, choose Port and hit Next
  5. For Protocol and Ports, select TCP protocol and type in 3306 for the Specific local ports and hit Next
  6. For Action, leave it at default which is Allow the connection and hit Next
  7. For Profile, you can leave it as default (everything checked by default) and hit Next
  8. For Name, set it to MySQL or any name that you will know what it is and click Finished

Setup users in MySQL for Kodi clients

  1. Open the "MySQL Command Line Client" from the MySQL start menu
  2. Enter the following commands:
    1. Type in: CREATE USER 'kodi' IDENTIFIED BY 'kodi'; and press return
    2. Type in: GRANT ALL ON *.* TO 'kodi'; and press return
    3. Type in: flush privileges; and press return
  3. Close out the command line tool

Note: If Kodi is unable to connect to the MySQL server, returning an error code [1130]:
If this occurs to you, try amending Step 2 above to read GRANT ALL ON *.* TO 'kodi'@'xxx.xxx.xxx.%'; 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.

[edit]

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:

After setting up a database server on you NAS, you should create a Kodi user with full administrative privileges. The user should be able to log in from your Kodi devices, so make sure you give the user login access from external machines. You do not need to create a database as Kodi will create the required databases itself.

Warning: As you are giving the Kodi user full administrative privileges and external machine access it is recommended that you review your database security. It is highly recommenced that you block internet access to your database using an appropriate firewall.


[edit]

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

How to

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


type the following commands

  • jls

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

  • jexec n csh

Install mysql

You are now inside your jail

  • pkg install mysql55-server
  • pkg install nano
    • (nano is a text editor you will need shortly)

We now need to enable mysql in rc.conf

  • nano /etc/rc.conf

insert the line below into the rc.conf file

  • mysql_enable="YES"

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

  • service mysql-server start

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.

  • mysql_secure_installation

Configure mysql ready for Kodi to use

type in

  • mysql -u root -p


You are now in mysql administration


  • CREATE USER 'kodi' IDENTIFIED BY 'kodi';
  • GRANT ALL ON *.* TO 'kodi';
  • flush privileges;
  • quit;
[edit]

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.

Upto MySQL Server 5.7 Server:

  1. GRANT ALL ON `MyVideos%`.* TO 'kodi'@'%' IDENTIFIED BY 'kodi';
  2. GRANT ALL ON `MyMusic%`.* TO 'kodi'@'%' IDENTIFIED BY 'kodi';

As per MySQL 8.0 Server and upwards:

  1. GRANT ALL PRIVILEGES ON `MyVideos%`.* TO `kodi`@`%`;
  2. GRANT ALL PRIVILEGES ON `MyMusic%`.* TO `kodi`@`%`;
Careful The limited grants on this page don't give the kodi user permissions to create required TRIGGERs during install or upgrade. Kodi requires these TRIGGERs to function properly.

Use the broader grant *.* statement that is explained on the previous tabs while creating or upgrading the tables. Only restrict rights afterwards, if you need to.

Alternatively, figure out how to specifically give the account the right to create the require TRIGGERS - this varies between MySQL versions.
Next step: Setting up Kodi