Tutorials/Shared Database: Difference between revisions

From KDE UserBase Wiki
No edit summary
m (Added emphasis, menuchoice)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Construction}}
<languages />
<translate>


== Shared Database == <!--T:1-->
<!--T:2-->
There are several desktop applications for KDE that deal with some kind of a database. The most popular are probably '''Amarok''' the music player, '''digiKam''' the photo manager, and '''Akonadi''' the personal information framework.
There are several desktop applications for KDE that deal with some kind of a database. The most popular are probably '''Amarok''' the music player, '''digiKam''' the photo manager, and '''Akonadi''' the personal information framework.
To simplify their installation and limit their requirements, each of these programs ship a database of their own, in most cases using SQLite. Having many separate databases creates unnecessary overhead, and makes it more difficult to back up your data.
To simplify their installation and limit their requirements, each of these programs ship a database of their own, in most cases using '''SQLite'''. Having many separate databases creates unnecessary overhead, and makes it more difficult to back up your data.


== Database server ==
=== Database server === <!--T:3-->


<!--T:4-->
The only database universally supported in these programs is '''MySQL''', so this is what we well use. It is also very easy to configure, either by command-line or with graphics tools.
The only database universally supported in these programs is '''MySQL''', so this is what we well use. It is also very easy to configure, either by command-line or with graphics tools.


=== Installation ===
==== Installation ==== <!--T:5-->


First, we have to install the mysql server. Linux users will probably want to install a package from their distribution, other can get it from their homepage at https://www.mysql.com/. Instructions to start MySQL at boot are distribution-specific, but since MySQL is a popular package, they shouldn't be hard to find. During the installation, the installer will probably ask you for a root password. Choose a secure password for this and remember it, this account will not be used by the desktop applications but only for database administration.
<!--T:6-->
First, we have to install the mysql server. Linux users will probably want to install a package from their distribution, other can get it from [https://www.mysql.com/ their homepage]. Instructions to start '''MySQL''' at boot are distribution-specific, but since '''MySQL''' is a popular package, they shouldn't be hard to find. During the installation, the installer will probably ask you for a root password. Choose a secure password for this and remember it, this account will not be used by the desktop applications but only for database administration.


=== Configuration ===
==== Configuration ==== <!--T:7-->


For the server configuration, this we will assume that your database server is not used over the network, contains no sensitive data, and that you trust your applications. If you plan to use this database for Akonadi data, it's best if you copy the configuration file from the Akonadi code repository, which can be downloaded at [https://projects.kde.org/projects/kdesupport/akonadi/repository/revisions/master/entry/server/src/storage/mysql-global.conf here]. Make a copy of your existing <code>/etc/mysql/my.cnf</code>, then replace it with the downloaded file.
<!--T:8-->
For the server configuration, this we will assume that your database server is not used over the network, contains no sensitive data, and that you trust your applications. If you plan to use this database for '''Akonadi''' data, it's best if you copy the configuration file from the '''Akonadi''' code repository, which can be downloaded at [https://projects.kde.org/projects/kdesupport/akonadi/repository/revisions/master/entry/server/src/storage/mysql-global.conf here]. Make a copy of your existing <code>/etc/mysql/my.cnf</code>, then replace it with the downloaded file.


<!--T:9-->
{{Warning| This file disables ''network access'' and ''user authentication''. The latter means that any application from your computer can connect to it without a password. This makes configuration of programs easier, and is well-suited for the general desktop use case.}}
{{Warning| This file disables ''network access'' and ''user authentication''. The latter means that any application from your computer can connect to it without a password. This makes configuration of programs easier, and is well-suited for the general desktop use case.}}


=== Creating the databases ===
==== Creating the databases ==== <!--T:10-->


The first thing we have to do once MySQL is installed and running is add a separate database for each program. I generally name them after the programs that use them. This can be done with either GUI administration tools, but since we only have to do it once it's probably faster to write a few commands:
<!--T:11-->
The first thing we have to do once '''MySQL''' is installed and running is add a separate database for each program. I generally name them after the programs that use them. This can be done with either GUI administration tools, but since we only have to do it once it's probably faster to write a few commands:
{{Input|1=$ mysql -u root -p}}
{{Input|1=$ mysql -u root -p}}
At the password prompt, type in the root password set when installing MySQL. Now, create the databases like this:
At the password prompt, type in the root password set when installing '''MySQL'''. Now we can start creating databases. For example, to create a database named 'amarok', type in this command:
{{Input|1=mysql> create database amarok;}}
{{Input|1=mysql> create database amarok;}}


== Amarok ==
=== Amarok === <!--T:12-->


Amarok requires very little configuration, but it doesn't provide a way to migrate your old database. Go to Settings => Configure Amarok... and go to the Database tab.
<!--T:13-->
Fill in 'localhost' as the server address, 3306 as the port, and 'amarok' as the database name.
'''Amarok''' requires very little configuration, but it doesn't provide a way to migrate your old database. Go to <menuchoice>Settings -> Configure Amarok...</menuchoice> and go to the <menuchoice>Database</menuchoice> tab.
Fill in <code>localhost</code> in the <menuchoice>Server</menuchoice> textfield, <code>3306</code> in <menuchoice>Port</menuchoice>, and <code>amarok</code> in <menuchoice>Database</menuchoice>.


<!--T:14-->
[[Image:Amarok-mysql-configuration.png|500px|center]]
[[Image:Amarok-mysql-configuration.png|500px|center]]


== digiKam ==
=== digiKam === <!--T:15-->


{{Note| digiKam used to have a bug which prevented the same from working in versions prior to 2.0, so you will need a newer version of the program. In version 2.0 is still doesn't work perfectly: it pops up an error message at startup, but the tables are populated and the album data is stored correctly. }}
<!--T:16-->
digiKam is somewhat special because it requires two databases: one for the images metadata, and one for thumbnails. Their names are not important, I chose to call them <code>digikam</code> and <code>digikam_thumb</code>:
{{Note|digiKam used to have a bug which prevented the same from working in versions prior to 2.0, so you will need a newer version of the program. In version 2.0 is still doesn't work perfectly: it pops up an error message at startup, but the tables are populated and the album data is stored correctly. }}
'''digiKam''' is somewhat special because it requires two databases: one for the images metadata, and one for thumbnails. Their names are not important, I chose to call them <code>digikam</code> and <code>digikam_thumb</code>:


<!--T:17-->
{{Input|1=mysql> create database digikam;
{{Input|1=mysql> create database digikam;
mysql> create database digikam_thumb;
mysql> create database digikam_thumb;
}}
}}


In digikam, the process is very similar to that of Amarok: Settings => Configure digiKam... => Database.
<!--T:18-->
In '''digiKam''', the process is very similar to that of '''Amarok'''. The settings are located in <menuchoice>Settings -> Configure digiKam... -> Database</menuchoice>.


<!--T:19-->
[[Image:digiKam-mysql-configuration.png|500px|center]]
[[Image:digiKam-mysql-configuration.png|500px|center]]


digiKam also comes with a handy database migration tool, available in Settings => Database Migration. Fill in your previous database settings (you don't have to do anything if you haven't changed these options) on the left side and your new settings on the right side, then click Migrate.
<!--T:20-->
'''digiKam''' also comes with a handy database migration tool, available in <menuchoice>Settings -> Database Migration</menuchoice>. Fill in your previous database settings (you don't have to do anything if you haven't changed these options) on the left side and your new settings on the right side, then click <menuchoice>Migrate</menuchoice>.


<!--T:21-->
[[Image:digiKam-mysql-migration.png|500px|center]]
[[Image:digiKam-mysql-migration.png|500px|center]]


== Akonadi ==
== Akonadi == <!--T:22-->


digiKam also comes with a handy database migration tool, available in Settings => Database Migration. Fill in your previous database settings (you don't have to do anything if you haven't changed these options) on the left side and your new settings on the right side, then click Migrate.
<!--T:23-->
First create a database for akonadi:
First create a database for '''Akonadi''':
{{Input|1=mysql -u root -p
{{Input|1=mysql -u root -p
create database akonadi;}}
create database akonadi;}}
Akonadi is not supposed to be a user-facing tool, so there is no configuration GUI for it. However, you can edit
'''Akonadi''' is not supposed to be a user-facing tool, so there is no configuration GUI for it. However, you can edit
<code>~/.config/akonadi/akonadiserverrc</code> to have these contents:
<code>~/.config/akonadi/akonadiserverrc</code> to have these contents:
</translate>


{{Input|1=[%General]
{{Input|1=[%General]
Line 68: Line 86:
ServerPath=/usr/bin/mysqld}}
ServerPath=/usr/bin/mysqld}}


<translate>
<!--T:26-->
Save the file, then log out and log in back again.
Save the file, then log out and log in back again.
<!--T:27-->
[[Category:Tutorials]]
[[Category:Advanced Users]]
</translate>

Latest revision as of 18:06, 16 September 2011

Shared Database

There are several desktop applications for KDE that deal with some kind of a database. The most popular are probably Amarok the music player, digiKam the photo manager, and Akonadi the personal information framework. To simplify their installation and limit their requirements, each of these programs ship a database of their own, in most cases using SQLite. Having many separate databases creates unnecessary overhead, and makes it more difficult to back up your data.

Database server

The only database universally supported in these programs is MySQL, so this is what we well use. It is also very easy to configure, either by command-line or with graphics tools.

Installation

First, we have to install the mysql server. Linux users will probably want to install a package from their distribution, other can get it from their homepage. Instructions to start MySQL at boot are distribution-specific, but since MySQL is a popular package, they shouldn't be hard to find. During the installation, the installer will probably ask you for a root password. Choose a secure password for this and remember it, this account will not be used by the desktop applications but only for database administration.

Configuration

For the server configuration, this we will assume that your database server is not used over the network, contains no sensitive data, and that you trust your applications. If you plan to use this database for Akonadi data, it's best if you copy the configuration file from the Akonadi code repository, which can be downloaded at here. Make a copy of your existing /etc/mysql/my.cnf, then replace it with the downloaded file.

Warning

This file disables network access and user authentication. The latter means that any application from your computer can connect to it without a password. This makes configuration of programs easier, and is well-suited for the general desktop use case.


Creating the databases

The first thing we have to do once MySQL is installed and running is add a separate database for each program. I generally name them after the programs that use them. This can be done with either GUI administration tools, but since we only have to do it once it's probably faster to write a few commands:

$ mysql -u root -p

At the password prompt, type in the root password set when installing MySQL. Now we can start creating databases. For example, to create a database named 'amarok', type in this command:

mysql> create database amarok;

Amarok

Amarok requires very little configuration, but it doesn't provide a way to migrate your old database. Go to Settings -> Configure Amarok... and go to the Database tab. Fill in localhost in the Server textfield, 3306 in Port, and amarok in Database.

digiKam

Note

digiKam used to have a bug which prevented the same from working in versions prior to 2.0, so you will need a newer version of the program. In version 2.0 is still doesn't work perfectly: it pops up an error message at startup, but the tables are populated and the album data is stored correctly.

digiKam is somewhat special because it requires two databases: one for the images metadata, and one for thumbnails. Their names are not important, I chose to call them digikam and digikam_thumb:

mysql> create database digikam;
mysql> create database digikam_thumb;

In digiKam, the process is very similar to that of Amarok. The settings are located in Settings -> Configure digiKam... -> Database.

digiKam also comes with a handy database migration tool, available in Settings -> Database Migration. Fill in your previous database settings (you don't have to do anything if you haven't changed these options) on the left side and your new settings on the right side, then click Migrate.

Akonadi

First create a database for Akonadi:

mysql -u root -p
create database akonadi;

Akonadi is not supposed to be a user-facing tool, so there is no configuration GUI for it. However, you can edit ~/.config/akonadi/akonadiserverrc to have these contents:

[%General]
Driver=QMYSQL

[QMYSQL]
Name=akonadi
Host=localhost
StartServer=false
Options=
ServerPath=/usr/bin/mysqld

Save the file, then log out and log in back again.