Amarok/Manual/Organization/Collection/ExternalDatabase: Difference between revisions

From KDE UserBase Wiki
m (use Amarok category instead of Amarik2.8)
 
(27 intermediate revisions by 8 users not shown)
Line 1: Line 1:
== Introduction ==
<languages/>
<translate>


Amarok 2.2 and above support an external '''MySQL''' database as a backend.
==== External Database ==== <!--T:1-->


== Configure Server ==
<!--T:2-->
'''Amarok''' 2.2 and above support an external '''MySQL''' database as a backend.


=== Install MySQL-Server ===
===== Configure Server ===== <!--T:3-->


First you need to install an '''MySQL'''-Server. On Debian-based distributions like Ubuntu you can use
===== Install MySQL-Server ===== <!--T:4-->
 
<!--T:5-->
First you need to install an '''MySQL''' server. On Debian-based distributions like Ubuntu you can use
{{Input|1=sudo apt-get install mysql-server mysql-client}}
{{Input|1=sudo apt-get install mysql-server mysql-client}}
to install it. You will be asked to specify a password for the root-account for the database. The ''mysql-client'' package is needed in order to execute some of the commands in this document, but it's not fundamental to the use of Amarok.
to install it. You will be asked to specify a password for the root-account for the database. The ''mysql-client'' package is needed in order to execute some of the commands in this document, but it's not fundamental to the use of '''Amarok'''.


=== Configure Database ===
===== Configure Database ===== <!--T:6-->


<!--T:7-->
Connect to the local database using
Connect to the local database using
{{Input|1=mysql -u root -p''}}
{{Input|1=mysql -u root -p}}
You will be prompted for the password for MySQL's '''root''' user. You will get the {{Output|1=mysql>}} prompt. <br />
You will be prompted for the password for '''MySQL's''' ''root'' user. You will get the {{Output|1=mysql>}} prompt.
 
<!--T:16-->
Create a new user '''''amarokuser''''' with the password '''''amarokpass''''' using the  
Create a new user '''''amarokuser''''' with the password '''''amarokpass''''' using the  
{{Input|1=CREATE USER '''<nowiki>'</nowiki>amarokuser<nowiki>'</nowiki>'''@'''<nowiki>'</nowiki>localhost<nowiki>'</nowiki>''' IDENTIFIED BY '''<nowiki>'</nowiki>amarokpass<nowiki>'</nowiki>''';}}
{{Input|1=CREATE USER '''<nowiki>'</nowiki>amarokuser<nowiki>'</nowiki>'''@'''<nowiki>'</nowiki>localhost<nowiki>'</nowiki>''' IDENTIFIED BY '''<nowiki>'</nowiki>amarokpass<nowiki>'</nowiki>''';}}
command. Amarok needs its own database, which is created with
command. Amarok needs its own database, which is created with
{{Input|1=CREATE DATABASE '''amarokdb''';''}}
{{Input|1=CREATE DATABASE '''amarokdb''';}}
Give the new user access to the database by entering the
Give the new user access to the database by entering the
{{Input|1=GRANT ALL ON '''amarokdb'''.* TO '''<nowiki>'</nowiki>amarokuser<nowiki>'</nowiki>'''@'''<nowiki>'</nowiki>%<nowiki>'</nowiki>''' IDENTIFIED BY '''<nowiki>'</nowiki>amarokpass<nowiki>'</nowiki>''';}}
{{Input|1=GRANT ALL ON '''amarokdb'''.* TO '''<nowiki>'</nowiki>amarokuser<nowiki>'</nowiki>'''@'''<nowiki>'</nowiki>%<nowiki>'</nowiki>''' IDENTIFIED BY '''<nowiki>'</nowiki>amarokpass<nowiki>'</nowiki>''';}}
command, where ''%'' is a wildcard to allow all hosts to connect to the database. Now use the
command, where ''%'' is a wildcard to allow all hosts to connect to the database. Now use the
{{Input|1=FLUSH PRIVILEGES;}}
{{Input|1=FLUSH PRIVILEGES;}}
statement to reload various internal caches used by MySQL. Finally
statement to reload various internal caches used by '''MySQL'''. Finally
{{Input|1=exit}}
{{Input|1=exit}}
closes the MySQL-prompt.<br />
closes the '''MySQL''' prompt.
By default the server can only be accessed by the local host. To change this you need to edit the file ''/etc/mysql/my.cnf'' and adjust the address near ''bind-address'' to the one your server listens on the network. '''0.0.0.0''' listens on all interfaces. After that you need to restart the server using
 
<!--T:17-->
By default the server can only be accessed by the local host. To change this you need to edit the file <tt>/etc/mysql/my.cnf</tt> and adjust the address near ''bind-address'' to the one your server listens on the network. '''0.0.0.0''' listens on all interfaces. After that you need to restart the server using
{{Input|1=sudo service mysql restart}}
{{Input|1=sudo service mysql restart}}


== Configure Client ==
===== Configure Client ===== <!--T:8-->
 
<!--T:9-->
Open the configuration dialog by clicking <menuchoice>Settings -> Configure Amarok -> Database</menuchoice>. Enable the checkbox and enter the user data.
 
 
<!--T:23-->
[[File:Amarok_2.8_ConfigurationDialogDatabaseEnabled.png|500px|thumb|center]]
 


Open the configuration dialog by clicking <menuchoice>Settings -> Configure Amarok... -> Database</menuchoice>. Enable the checkbox and enter the user data.<br />
<br />
[[File:remotecollections_client.png|500px|thumb|center]]<br />
<br />
You need to restart Amarok so that the changes take effect.


== Migrating from MySQL Embedded to MySQL Server ==
<!--T:24-->
You need to restart '''Amarok''' so that the changes take effect.


===== Migrating from MySQL Embedded to MySQL Server ===== <!--T:10-->
<!--T:11-->
If you want to maintain the statistics, etc. that you have in the embedded '''MySQL''' database from before '''Amarok''' 2.2, you can do the following:
If you want to maintain the statistics, etc. that you have in the embedded '''MySQL''' database from before '''Amarok''' 2.2, you can do the following:
First, start '''Amarok''' 2.2 at least once to give the database a chance to update to the latest schema version.
First, start '''Amarok''' 2.2+ at least once to give the database a chance to update to the latest schema version.


<!--T:12-->
Next, kill the running '''MySQL''' service
Next, kill the running '''MySQL''' service
{{Input|1=sudo /etc/init.d/mysql stop}}
{{Input|1=sudo /etc/init.d/mysql stop}}
and start a '''MySQL''' daemon from your ''~/.kde4/share/apps/amarok'' directory (--defaults-file MUST be the first option!):
and start a '''MySQL''' daemon from your <tt>~/.kde4/share/apps/amarok</tt> directory (--defaults-file MUST be the first option!):
 
<!--T:18-->
{{Input|1=/usr/sbin/mysqld --defaults-file=`pwd`/my.cnf --default-storage-engine=MyISAM --datadir=`pwd`/mysqle --socket=`pwd`/sock --skip-grant-tables}}
{{Input|1=/usr/sbin/mysqld --defaults-file=`pwd`/my.cnf --default-storage-engine=MyISAM --datadir=`pwd`/mysqle --socket=`pwd`/sock --skip-grant-tables}}
<!--T:19-->
The skip-grant-tables means you can use any password or username to connect to it. 'localhost' will not work, the '''MySQL''' client will try to use a '''Unix''' socket. Using '''127.0.0.1''' as the host makes it work. Some systems may restrict this access through apparmor or SELinux. They can be temporarily disabled with  
The skip-grant-tables means you can use any password or username to connect to it. 'localhost' will not work, the '''MySQL''' client will try to use a '''Unix''' socket. Using '''127.0.0.1''' as the host makes it work. Some systems may restrict this access through apparmor or SELinux. They can be temporarily disabled with  
{{Input|1=sudo /etc/init.d/apparmor stop}}
{{Input|1=sudo /etc/init.d/apparmor stop}}
<!--T:20-->
Now, run mysqldump, passing in the -S option to specify the local socket.  This will dump your old embedded DB out to a SQL file.
Now, run mysqldump, passing in the -S option to specify the local socket.  This will dump your old embedded DB out to a SQL file.
{{Input|1=mysqldump -S sock amarok > amarok.mysql}}
{{Input|1=mysqldump -S sock amarok > amarok.mysql}}
<!--T:21-->
You can then restart your '''MySQL''' service and load this SQL file into your '''MySQL''' server. You'll have needed to already run the GRANT statement above and create an '''Amarok''' database ("CREATE DATABASE amarok;"):
You can then restart your '''MySQL''' service and load this SQL file into your '''MySQL''' server. You'll have needed to already run the GRANT statement above and create an '''Amarok''' database ("CREATE DATABASE amarok;"):
<!--T:22-->
{{Input|1=sudo /etc/init.d/mysql stop
{{Input|1=sudo /etc/init.d/mysql stop
mysql -u amarokuser -p amarok < amarok.mysql}}
mysql -u amarokuser -p amarok < amarok.mysql}}


{{Note|1=You may need to re-scan your collection in Amarok after completing this.}}
<!--T:13-->
{{Note|1=You may need to re-scan your collection in '''Amarok''' after completing this.}}


<!--T:14-->
{{Prevnext2
{{Prevnext2
| prevpage=Amarok/Manual/AdvancedFeatures/DynamicPlaylists | nextpage=Amarok/Manual/AdvancedFeatures/AFT
| prevpage=Special:myLanguage/Amarok/Manual/Organization/Collection/RemoteCollections/UPnP | nextpage=Special:myLanguage/Amarok/Manual/Organization/Collection/WorkingWithMediaDevices
| prevtext=Dynamic Playlists | nexttext=AFT
| prevtext=UPnP | nexttext=Working with Media Devices
| index=Amarok/Manual | indextext=Back to Menu
| index=Special:myLanguage/Amarok/Manual | indextext=Back to Menu
}}
}}
<!--T:15-->
[[Category:Amarok]]
[[Category:Multimedia]]
[[Category:Tutorials]]
</translate>

Latest revision as of 17:52, 3 March 2019

External Database

Amarok 2.2 and above support an external MySQL database as a backend.

Configure Server
Install MySQL-Server

First you need to install an MySQL server. On Debian-based distributions like Ubuntu you can use

sudo apt-get install mysql-server mysql-client

to install it. You will be asked to specify a password for the root-account for the database. The mysql-client package is needed in order to execute some of the commands in this document, but it's not fundamental to the use of Amarok.

Configure Database

Connect to the local database using

mysql -u root -p

You will be prompted for the password for MySQL's root user. You will get the

mysql>

prompt.

Create a new user amarokuser with the password amarokpass using the

CREATE USER 'amarokuser'@'localhost' IDENTIFIED BY 'amarokpass';

command. Amarok needs its own database, which is created with

CREATE DATABASE amarokdb;

Give the new user access to the database by entering the

GRANT ALL ON amarokdb.* TO 'amarokuser'@'%' IDENTIFIED BY 'amarokpass';

command, where % is a wildcard to allow all hosts to connect to the database. Now use the

FLUSH PRIVILEGES;

statement to reload various internal caches used by MySQL. Finally

exit

closes the MySQL prompt.

By default the server can only be accessed by the local host. To change this you need to edit the file /etc/mysql/my.cnf and adjust the address near bind-address to the one your server listens on the network. 0.0.0.0 listens on all interfaces. After that you need to restart the server using

sudo service mysql restart
Configure Client

Open the configuration dialog by clicking Settings -> Configure Amarok -> Database. Enable the checkbox and enter the user data.



You need to restart Amarok so that the changes take effect.

Migrating from MySQL Embedded to MySQL Server

If you want to maintain the statistics, etc. that you have in the embedded MySQL database from before Amarok 2.2, you can do the following: First, start Amarok 2.2+ at least once to give the database a chance to update to the latest schema version.

Next, kill the running MySQL service

sudo /etc/init.d/mysql stop

and start a MySQL daemon from your ~/.kde4/share/apps/amarok directory (--defaults-file MUST be the first option!):

/usr/sbin/mysqld --defaults-file=`pwd`/my.cnf --default-storage-engine=MyISAM --datadir=`pwd`/mysqle --socket=`pwd`/sock --skip-grant-tables

The skip-grant-tables means you can use any password or username to connect to it. 'localhost' will not work, the MySQL client will try to use a Unix socket. Using 127.0.0.1 as the host makes it work. Some systems may restrict this access through apparmor or SELinux. They can be temporarily disabled with

sudo /etc/init.d/apparmor stop

Now, run mysqldump, passing in the -S option to specify the local socket. This will dump your old embedded DB out to a SQL file.

mysqldump -S sock amarok > amarok.mysql

You can then restart your MySQL service and load this SQL file into your MySQL server. You'll have needed to already run the GRANT statement above and create an Amarok database ("CREATE DATABASE amarok;"):

sudo /etc/init.d/mysql stop
mysql -u amarokuser -p amarok < amarok.mysql

Note

You may need to re-scan your collection in Amarok after completing this.