<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr" lang="en"><head>

  
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="keywords" content="MySQL HowTo,De:MySQL HowTo,Es:MySQL HowTo,It:MySQL HowTo">
<link rel="shortcut icon" href="http://amarok.kde.org/favicon.ico"><title>MySQL HowTo - Amarok Wiki</title>
    
    <link rel="stylesheet" type="text/css" media="all" href="MySQL_HowTo_files/base.css">
    <link rel="stylesheet" type="text/css" media="all" href="MySQL_HowTo_files/wiki.css">
    <link rel="stylesheet" type="text/css" media="all" href="MySQL_HowTo_files/custom.css">
    <link rel="stylesheet" type="text/css" media="print" href="MySQL_HowTo_files/wikiprint.css"><!--[if lt IE 5.5000]><style type="text/css">@import "/amarokwiki/skins/kde/IE50Fixes.css";</style><![endif]--><!--[if IE 5.5000]><style type="text/css">@import "/amarokwiki/skins/kde/IE55Fixes.css";</style><![endif]--><!--[if gte IE 6]><style type="text/css">@import "/amarokwiki/skins/kde/IE60Fixes.css";</style><![endif]--><!--[if IE]><script type="text/javascript" src="/amarokwiki/skins/common/IEFixes.js"></script>
    <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
    
    
    
    
    <script type="text/javascript" src="MySQL_HowTo_files/index.php"></script>    <script type="text/javascript" src="MySQL_HowTo_files/wikibits.js"></script>
    <style type="text/css">/*<![CDATA[*/
@import "/amarokwiki/index.php?title=MediaWiki:Common.css&action=raw&ctype=text/css&smaxage=18000";
@import "/amarokwiki/index.php?title=MediaWiki:Kde.css&action=raw&ctype=text/css&smaxage=18000";
@import "/amarokwiki/index.php?title=-&action=raw&gen=css&maxage=18000";
/*]]>*/</style>                <script type="text/javascript" src="MySQL_HowTo_files/devmo.js"></script>
    <script type="text/javascript" src="MySQL_HowTo_files/prototype.js"></script>
    <script type="text/javascript" src="MySQL_HowTo_files/scriptaculous.js"></script>

<script src="MySQL_HowTo_files/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-80978-7";
urchinTracker();
</script></head><body class="ns-0">

  <div id="container">
    <p class="skipLink"><a href="#content" accesskey="2">Skip to main content</a></p>
    <div id="kde-org"><a href="http://www.kde.org/">Visit KDE.org</a></div>

  <div id="header">
    <h1><a href="http://amarok.kde.org/wiki" title="Return to home page" accesskey="1">KDE</a></h1>
  </div>
    <div id="page">
    <!-- Navigation -->
    <div id="navigation">
        <div id="bar">
            <div>
                <ul id="personal">
                    <li id="pt-login">
                    </li>
                </ul>
                <ul id="contenttypes">
<!--                     <li class="selected"> -->
                    <li>
                        <a href="http://amarok.kde.org/wiki">Main Page</a>
                    </li>
                    <li>
                        <a href="http://amarok.kde.org/wiki/Download">Download</a>
                    </li>
<!--                    <li class="beta">
                        <a href="http://amarok.kde.org/wiki/Download_Beta">Beta</a>
                    </li>-->
                    <li>
                        <a href="http://amarok.kde.org/wiki/FAQ">FAQ</a>
                    </li>
                    <li>
                        <a href="http://amarok.kde.org/wiki/RoadMap">RoadMap</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>


        <div id="sidebar">
        <!-- search box -->
	<form name="searchform" action="/wiki/Special:Search" id="searchform">
	    <input id="searchInput" name="search" accesskey="f" value="" type="text">
	    <input name="go" class="searchButton" id="searchGoButton" value="Go" type="submit">&nbsp;<input name="fulltext" class="searchButton" value="Search" type="submit">
        </form>
        <!-- end searchbox -->
	
	    <div class="pagetools">
                <div>
<!--                     <h3>Navigation</h3> -->
                    <ul>
                        <li class="nav" id="pt-login"><a href="http://amarok.kde.org/amarokwiki/index.php?title=Special:Userlogin&amp;returnto=MySQL_HowTo">Log in / create account</a></li>                    </ul>
                </div>
            </div>

            <!-- VIEWS -->
            <div class="pagetools">
                <div>
<!--                     <h3>Views</h3> -->
                    <ul>
                        <li id="ca-nstab-main" class="nav"><a href="http://amarok.kde.org/wiki/MySQL_HowTo">Article</a></li><li class="nav" id="ca-talk"><a href="http://amarok.kde.org/wiki/Talk:MySQL_HowTo">Discussion</a></li><li class="nav" id="ca-edit"><a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit">Edit</a></li><li class="nav" id="ca-history"><a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=history">History</a></li>                    </ul>
                </div>
            </div>

            <!-- TOOLBOX -->
<!--navigation	  Navigation		    	      n-recentchanges/wiki/Special:Recentchanges">Recent changes	     	-->
            <div class="pagetools">
                <div>
<!--                     <h3>Toolbox</h3> -->
                    <ul>
	    	      <li class="nav" id="n-recentchanges"><a href="http://amarok.kde.org/wiki/Special:Recentchanges">Recent changes</a></li>
	                                                     <li class="nav" id="t-whatlinkshere">
                            <a href="http://amarok.kde.org/amarokwiki/index.php?title=Special:Whatlinkshere&amp;target=MySQL_HowTo">What links here</a>
                        </li>
                                                <li class="nav" id="t-recentchangeslinked">
                            <a href="http://amarok.kde.org/amarokwiki/index.php?title=Special:Recentchangeslinked&amp;target=MySQL_HowTo">Related changes</a>
                        </li>
                        
                                                                        <li class="nav" id="t-upload">
                            <a href="http://amarok.kde.org/wiki/Special:Upload">Upload file</a>
                        </li>
                                                                                                <li class="nav" id="t-specialpages">
                            <a href="http://amarok.kde.org/wiki/Special:Specialpages">Special pages</a>
                        </li>
                                                
                                                <li class="nav" id="t-print">
                            <a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;printable=yes">Printable version</a>
                        </li>
                                            </ul>
                </div>
            </div>
        </div>

        <!-- Begin Content -->

        <div id="content">
            <div class="article">
            <a name="top" id="contentTop"></a>
<!-- removed for liftig the interface [1]
            <h1 class="firstHeading">MySQL HowTo</h1>
-->
            <h3 id="siteSub">From Amarok Wiki</h3>
            <div id="contentSub"></div>
            <div class="mainpage">
                                                <!-- start content -->
                <div class="MainPageBG" style="border: 2px solid rgb(170, 170, 170); margin: 0.3em; padding: 0.25em; background-color: rgb(255, 255, 255);">
<p style="margin: auto; width: 95%; font-size: 83.3%; text-align: center;">
<span lang="de"><a href="http://amarok.kde.org/wiki/De:MySQL_HowTo" title="De:MySQL HowTo">Deutsch</a></span> |
<span lang="en"><strong class="selflink">English</strong></span> |
<span lang="es"><a href="http://amarok.kde.org/wiki/Es:MySQL_HowTo" title="Es:MySQL HowTo">Castellano</a></span> |
<span lang="it"><a href="http://amarok.kde.org/wiki/It:MySQL_HowTo" title="It:MySQL HowTo">Italiano</a></span>
</p>
</div><br>
<table id="toc" class="toc" summary="Contents"><tbody><tr><td><div id="toctitle"><h2>Contents</h2> <span class="toctoggle">[<a href="javascript:toggleToc()" class="internal" id="togglelink">hide</a>]</span></div>
<ul>
<li class="toclevel-1"><a href="#Configuration"><span class="tocnumber">1</span> <span class="toctext">Configuration</span></a>
<ul>
<li class="toclevel-2"><a href="#Amarok_Support"><span class="tocnumber">1.1</span> <span class="toctext">Amarok Support</span></a></li>
<li class="toclevel-2"><a href="#MySQL_Setup"><span class="tocnumber">1.2</span> <span class="toctext">MySQL Setup</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="#Database_Conversions"><span class="tocnumber">2</span> <span class="toctext">Database Conversions</span></a>
<ul>
<li class="toclevel-2"><a href="#SQLite_-.3E_MySQL"><span class="tocnumber">2.1</span> <span class="toctext">SQLite -&gt; MySQL</span></a></li>
<li class="toclevel-2"><a href="#MySQL_-.3E_SQLite"><span class="tocnumber">2.2</span> <span class="toctext">MySQL -&gt; SQLite</span></a></li>
</ul>
</li>
<li class="toclevel-1"><a href="#Automatic_Backups"><span class="tocnumber">3</span> <span class="toctext">Automatic Backups</span></a></li>
<li class="toclevel-1"><a href="#Restore_From_an_Automatic_Backup"><span class="tocnumber">4</span> <span class="toctext">Restore From an Automatic Backup</span></a></li>
<li class="toclevel-1"><a href="#Repair_a_Corrupted_Database"><span class="tocnumber">5</span> <span class="toctext">Repair a Corrupted Database</span></a></li>
<li class="toclevel-1"><a href="#Tips_for_Sharing_a_MySQL_Database"><span class="tocnumber">6</span> <span class="toctext">Tips for Sharing a MySQL Database</span></a></li>
</ul>
</td></tr></tbody></table><script type="text/javascript"> if (window.showTocToggle) { var tocShowText = "show"; var tocHideText = "hide"; showTocToggle(); } </script>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=1" title="Edit section: Configuration">edit</a>]</div><a name="Configuration"></a><h1> Configuration </h1>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=2" title="Edit section: Amarok Support">edit</a>]</div><a name="Amarok_Support"></a><h2> Amarok Support </h2>
<p>Amarok 1.2 and above support a MySQL database backend in addition to
the built-in SQLite database engine. To get MySQL support compiled-in,
you need to specify "--enable-mysql" as a configure parameter and
re-run "make install" as root. Your configure line probably will look
something like this:
</p>
<pre>$ ./configure --enable-mysql
</pre>
<p>Please also make sure you have the libmysqlclient libraries, along with the development headers (-dev packages) installed.
</p>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=3" title="Edit section: MySQL Setup">edit</a>]</div><a name="MySQL_Setup"></a><h2> MySQL Setup </h2>
<p>Amarok 1.4 requires MySQL 4.0 or better, and is known to work with
MySQL versions up to 5.0.22 (but, at the time of writing, not 5.0.24).
Since Amarok-1.4.2 MySQL-5.0.24 also works.
</p><p>Older versions of Amarok may work best with MySQL versions &lt;
5.0. One known problem as a result of this is Amarok's DB continually
growing and adding multiple entries for every track on each rescan.
</p><p><br>
Make sure the MySQL daemon is running. If necessary, add it to your linux startup scripts, via whatever method your distro uses.
</p><p>Create a root password for MySQL, if you have not already done so.
</p>
<pre>$ mysql -u root 
set password for root@localhost = password('xxxxxxx'); 
flush privileges; 
quit; 
</pre>
<p>Of course change xxxxxx to the password you want.
</p><p>Once you have done that, you must create a MySQL database
through any usual method. You can just use the "mysql" command: (it
will ask for your MySQL root password)
</p>
<pre>$ mysql -p -u root
CREATE DATABASE amarok;
USE mysql;
GRANT ALL ON amarok.* TO amarok@localhost IDENTIFIED BY 'PASSWORD_CHANGE_ME';
FLUSH PRIVILEGES;
</pre>
<p>In the above example, a database called "amarok" was created, and a
user called amarok can access it from localhost using the password
"PASSWORD_CHANGE_ME". To allow access from remote hosts, use
amarok@'%'.
</p><p>It is very important that you 'GRANT ALL' privileges to the
"amarok" user. In particular, Amarok needs ALTER privileges on its
database.
</p><p>Once a database exists, open the Configure Amarok screen (found
in the Settings menu), and go to the Collection tab. Change the
drop-down menu from SQLite to MySQL. You will have to specify the host
(probably localhost), port (probably 3306), and the name of the db that
you have created for it. Additionally, the username and password of a
user who has write access to the given database needs to be specified
(above, the user is amarok, and the password is PASSWORD_CHANGE_ME).
</p><p>Remote MySQL Server Gotcha: Most MySQL installs have the daemon listening only to localhost by default. 
</p><p>So if you get errors about not being able to connect to the
server or database, (_not_ password related errors) then you will have
to edit my.cnf on the host machine (/etc/mysql/my.cnf, most likely),
comment out the "bind_address" variable and restart MySQL. You may have
to comment out "skip_networking", so that MySQL will listen on a tcp
socket.
</p><p>AFIAK there is no way of tweaking which interfaces it listens
on. It listens on only 1 or on all. You should then update your
firewall accordingly.
</p>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=4" title="Edit section: Database Conversions">edit</a>]</div><a name="Database_Conversions"></a><h1> Database Conversions </h1>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=5" title="Edit section: SQLite -&amp;gt; MySQL">edit</a>]</div><a name="SQLite_-.3E_MySQL"></a><h2>  SQLite -&gt; MySQL </h2>
<p>An (unsupported) way to transfer your SQLite3 database to MySQL:
</p>
<pre>cd ~/.kde/share/apps/amarok &amp;&amp; \
sqlite3 collection.db .dump | \ 
grep -v "BEGIN TRANSACTION;" | \
grep -v "COMMIT;" | \
perl -pe 's/INSERT INTO \"(.*)\" VALUES/INSERT INTO \1 VALUES/' | 
mysql -u root -p amarok
</pre>
<p>Some had trouble with the previous script that was here, but the
above version worked. If you get an error, (album names with
backslashes can cause problems) then drop the last line above and
output the results to a file. </p>
<pre>cd ......\1 VALUES/' &gt; ~/tmp/amarok_dump
</pre>
<p>Edit the file to fix the errors in whatever handy text editor you
prefer. Delete any tables that were created in the Amarok database (I
used phpMyAdmin, but if you want to do this via MySQL commands and
don't know how... seek information in <a href="http://dev.mysql.com/doc/refman/5.0/en/" class="external text" title="http://dev.mysql.com/doc/refman/5.0/en/" rel="nofollow">the MySQL Reference Manual</a>). Then try the last part again using your output file.
</p>
<pre>cat ~/tmp/amarok_dump | mysql -u root -p amarok
</pre>
<p>The original script tried to commit the following substitution:
s/VARCHAR\(256\)/VARCHAR\(255\)/
however my SQLite dump file only had VARCHAR(255) references. You might
want to check yours to make sure by running something like:
</p>
<pre>grep "VARCHAR(256)" ~/tmp/amarok_dump
</pre>
<p>If you get any results then try to fix them with:
</p>
<pre>perl -pe 's/VARCHAR\(256\)/VARCHAR\(255\)/' &lt; ~/tmp/amarok_dump &gt; ~/tmp/amarok_dump2 &amp;&amp; mv ~/tmp/amarok_dump2 ~/tmp/amarok_dump
</pre>
<p>MySQL also comes by default with a useful command line utility called replace, which can replace multiple strings within a file:
</p>
<pre>replace "VARCHAR(256)" "VARCHAR(255)" -- ~/tmp/amarok_dump
</pre>
<p>You can also specify several pairs of strings for the search/replace provided you remember to terminate the line with:
</p>
<pre>-- ~/tmp/amarok_dump
</pre>
<p>An alternate method is to import my SQLite data as follows:
</p>
<ul><li> Start Amarok, change to MySQL, and build the database (but don't play any songs)
</li><li> Download <a href="http://sourceforge.net/projects/sqlitebrowser/" class="external text" title="http://sourceforge.net/projects/sqlitebrowser/" rel="nofollow">SQLite Database Browser</a>
</li><li> Export the statistics database to a dump file, amarok_dump.sql
</li><li> Remove all BEGIN TRANSACTION, COMMIT and CREATE sql commands
</li><li> Import the file using MySQL:
</li></ul>
<pre>cat amarok_dump.sql | mysql -u root -p amarok
</pre>
<p>If you receive any errors, its possible that you played some songs
and a statistics entry already exists for a particular file. If this is
the case, you will have to edit amarok_dump.sql, find the offending
line and remove EVERYTHING before it (since those commands have already
been executed by MySQL - you will get errors otherwise). If you want to
still use the offending line, replace INSERT INTO with REPLACE INTO. Re
run the above command.
</p>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=6" title="Edit section: MySQL -&amp;gt; SQLite">edit</a>]</div><a name="MySQL_-.3E_SQLite"></a><h2> MySQL -&gt; SQLite </h2>
<p>An (unsupported) way to transfer your MySQL database to SQLite3:
</p><p>(<b>Note this will not currently work with Amarok &gt;= 1.4.2 due to changes in the schema</b>)
</p>
<pre>cd ~/.kde/share/apps/amarok &amp;&amp; \
mv collection.db collection.db.old &amp;&amp; \
mysqldump -uroot -p -n -t amarok | sed -e "s/\\\'/\'\'/g" | sed -e "s/\\\\\"/\"\"/g" &gt; amarok.sql &amp;&amp; \
sqlite3 collection.db
</pre>
<p>paste to your "sqlite&gt;" prompt to create the tables:
</p>
<pre>CREATE TABLE album (id INTEGER PRIMARY KEY ,name VARCHAR(255) );
CREATE TABLE artist (id INTEGER PRIMARY KEY ,name VARCHAR(255) );
CREATE TABLE directories (dir VARCHAR(255) UNIQUE,changedate INTEGER );
CREATE TABLE genre (id INTEGER PRIMARY KEY ,name VARCHAR(255) );
CREATE TABLE images (path VARCHAR(255),artist VARCHAR(255),album VARCHAR(255) );
CREATE TABLE related_artists (artist VARCHAR(255),suggestion VARCHAR(255),changedate INTEGER );
CREATE TABLE statistics (url VARCHAR(255) UNIQUE,createdate INTEGER,accessdate INTEGER,percentage FLOAT,playcounter INTEGER,rating INTEGER);
CREATE TABLE tags (url VARCHAR(255),dir VARCHAR(255),createdate INTEGER,album INTEGER,artist INTEGER,genre INTEGER,title VARCHAR(255),year INTEGER,comment VARCHAR(255),track NUMERIC(4),bitrate INTEGER,length INTEGER,samplerate INTEGER,sampler BOOL );
CREATE TABLE year (id INTEGER PRIMARY KEY ,name VARCHAR(4) );
CREATE INDEX album_idx ON album( name );
CREATE INDEX album_tag ON tags( album );
CREATE INDEX artist_idx ON artist( name );
CREATE INDEX artist_tag ON tags( artist );
CREATE INDEX directories_dir ON directories( dir );
CREATE INDEX genre_idx ON genre( name );
CREATE INDEX genre_tag ON tags( genre );
CREATE INDEX images_album ON images( album );
CREATE INDEX images_artist ON images( artist );
CREATE INDEX percentage_stats ON statistics( percentage );
CREATE INDEX playcounter_stats ON statistics( playcounter );
CREATE INDEX related_artists_artist ON related_artists( artist );
CREATE INDEX sampler_tag ON tags( sampler );
CREATE INDEX url_stats ON statistics( url );
CREATE INDEX url_tag ON tags( url );
CREATE INDEX year_idx ON year( name );
CREATE INDEX year_tag ON tags( year );
</pre>
<p>and import your mysqldump at your "sqlite&gt;" prompt:
</p>
<pre>.read amarok.sql
</pre>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=7" title="Edit section: Automatic Backups">edit</a>]</div><a name="Automatic_Backups"></a><h1> Automatic Backups </h1>
<p><b>Note: it is also necessary to backup ~/.kde/share/config/amarokrc as this contains important database version information.</b>
</p><p>This can be done easily using a cron job.
Create a shell script and place it in your /etc/cron.weekly directory (or your cron directory).
</p>
<pre> #!/bin/sh
 # Backup the Amarok MySQL database
 
 ######### CHANGE SETTINGS HERE #########
 # Location to place Amarok-database backups:
 BACKUP_BASE_DIR=~/backup
 
 # Name of MySQL-Datenbank:
 AMAROKDB_NAME=amarok
 
 # Name and Passwort for Amarok-MySQL-Database:
 AMAROKDB_USER=amarok
 AMAROKDB_PW=PASSWORD
 
 # Location of amarokrc:
 AMAROKRC=~/.kde/share/config/amarokrc
 ######### END OF SETTINGS SECTION #########
 
 BACKUP_SUBDIRECTORY=`date +%Y-%m-%d`
 
 if [[ ! ( -w $BACKUP_BASE_DIR &amp;&amp; -d $BACKUP_BASE_DIR ) ]]
 then
   echo -e "\n\n $BACKUP_BASE_DIR doesn't exist or is not writable!\n"
   echo -e "STOP.\n"
   exit 1;
 fi
 
 if [ ! -r $AMAROKRC ]
 then
   echo -e "\n\n $AMAROKRC doesn't exist or Amarok is not installed!\n"
   echo -e "STOP.\n"
   exit 1;
 fi
 
 mkdir -p $BACKUP_BASE_DIR/amarok/$BACKUP_SUBDIRECTORY
                #using a temporary file in order not to overwrite an existing copy when the script is 
                #manually invoked a second time (e.g. right before restoration of existing backup of same date!)
 mysqldump -u $AMAROKDB_USER -p$AMAROKDB_PW $AMAROKDB_NAME &gt; /tmp/amarokdb.mysqldump.temp
 mv -i -v /tmp/amarokdb.mysqldump.temp $BACKUP_BASE_DIR/amarok/$BACKUP_SUBDIRECTORY/amarok.mysql
 
 # Auch die Konfigurationsdatei amarokrc wird gesichert:
 cp -i -v $AMAROKRC $BACKUP_BASE_DIR/amarok/$BACKUP_SUBDIRECTORY
 
</pre>
<p>This script will create a directory by date in '~/backup/amarok' and
store a MySQL dump and a copy of the configuration file
'~/.kde/share/config/amarokrc' into it. This assumes the username is
'amarok' and the database name is 'amarok'. In the settings section,
replace "PASSWORD" by your password and the names as necessary. It will
also require you to GRANT ALL in your permissions for the Amarok user.
</p>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=8" title="Edit section: Restore From an Automatic Backup">edit</a>]</div><a name="Restore_From_an_Automatic_Backup"></a><h1> Restore From an Automatic Backup </h1>
<p>Restoring from a previous backup can be done in a few steps. First,
remove any old databases and create a new amarok database (this example
uses the same naming convensions as the above backup script):
</p>
<pre>$ mysql -p -u root -h localhost
DROP DATABASE amarok;
CREATE DATABASE amarok;
QUIT;
</pre>
<p>Next, we need to restore the backup.  Lets assume we have one from July 12th, 2006:
</p>
<pre>$ mysql -p -u amarok -h localhost amarok &lt; /home/backup/amarok/2006-07-12/amarok.mysql
</pre>
<p>Now your database should be restored. Note that the first instance
of 'amarok' is the username and the second instance is the database
name.
</p><p><b>It is also necessary to restore ~/.kde/share/config/amarokrc as this contains important database version information.</b>
</p>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=9" title="Edit section: Repair a Corrupted Database">edit</a>]</div><a name="Repair_a_Corrupted_Database"></a><h1> Repair a Corrupted Database </h1>
<p>When your database is corrupted, you cannot see all your songs in
the collection browser, and you could see in /var/log/messages that the
MySQL database is corrupted. To repair the database, launch the
mysqlcheck command as root:
</p>
<pre>mysqlcheck -p --auto-repair --all-databases
</pre>
<p>Then rescan your collection to update the database.
</p>
<div class="editsection" style="float: right; margin-left: 5px;">[<a href="http://amarok.kde.org/amarokwiki/index.php?title=MySQL_HowTo&amp;action=edit&amp;section=10" title="Edit section: Tips for Sharing a MySQL Database">edit</a>]</div><a name="Tips_for_Sharing_a_MySQL_Database"></a><h1> Tips for Sharing a MySQL Database </h1>
<ul><li> It is *most* important that all machines that are sharing your
database have the music files mounted on exactly the same path. At the
same time, make sure all copies of Amarok are configured with exactly
the same folders checked. If either the paths or the folders differ,
your different instances of Amarok will be constantly rescanning the
collection.
</li></ul>
<ul><li> Make sure you use exactly the same version of amarok on all machines sharing the database.
</li></ul>
<ul><li> Use a wrapper script on the amarok binary to prevent it from
starting (and thus wiping your database) if your music mount(s) isn't
available. </li></ul>
<ul><li> Restrict incremental updating via "Watch folders for changes"
(On the Amarok settings, Collection page) to just one machine. This
way, when new music is added, only one machine will scan it into the
database. Alternatively, you can disable incremental scanning on all
machines, and run a manual collection rescan whenever you like (Tools
Menu, Rescan Collection).
</li></ul>
<ul><li> Make sure all computers have the same Amarok database name/username/password set.
</li></ul>
<p>(It may be possible to set up multiple users with access to the Amarok database)
</p>
<ul><li> IMPORTANT NOTE: Since the introduction of Dynamic Collections
in Amarok 1.4.2, if you wish to use a shared database, you will need to
add </li></ul>
<pre>DynamicCollection=false</pre>
to the [Collection] section of <pre>~/.kde/share/config/amarokrc</pre>
<p>as posted <a href="http://bugs.kde.org/show_bug.cgi?id=136826" class="external text" title="http://bugs.kde.org/show_bug.cgi?id=136826" rel="nofollow">here</a>
</p>
<!-- Saved in parser cache with key amarok:pcache:idhash:925-0!1!0!0!!en!2 and timestamp 20061211070541 -->
<div class="printfooter">
Retrieved from "<a href="http://amarok.kde.org/wiki/MySQL_HowTo">http://amarok.kde.org/wiki/MySQL_HowTo</a>"</div>
                <!-- end content -->
            </div>
        </div>

        <!-- end of the website -->

	
        <div id="footer">
	     <ul>
<!--            <li id="f-lastmod"> This page was last modified 07:00, 10 December 2006.</li>                <li id="f-viewcount">This page has been accessed 87,144 times.</li> -->
		<br>
             </ul>
             <ul>
		<a href="http://amarok.kde.org/" class="external text" title="http://amarok.kde.org" rel="nofollow">Amarok Homepage</a>
		 | <a href="http://amarok.kde.org/wiki/AmaroK_Web_Resources" title="AmaroK Web Resources">Amarok Web Resources</a>
<!--                             <li id="f-about"><a href="/wiki/Amarok_Wiki:About" title="Amarok Wiki:About">About Amarok Wiki</a></li> -->
            </ul>
        </div>

        <!-- Served by amarok.kde.org in 20.433 secs. -->    </div></div></div></body></html>