Skip navigation.

Raphael's Blog

A look into a programmer and administrator's life

Amarok: sqlite->mysql

,

Amarok's
MySQL HowTo
shows some ways to move from sqlite to mysql the collection database. This is the way I did:

Let's start with the first way:


cd ~/.kde/share/apps/amarok && \
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



not bad, but there are some glitches :down: :
  • The sqlite3 ... line contains a space at the end, which makes the command fail (can't be noticed on this blog post, but check the HowTo and you'll see what I mean)
  • You will get error messages like ERROR 1071 (42000) at line 25380: Specified key was too long; max key length is 1000 bytes
  • Replacing every VARCHAR(1024) with VARCHAR(996) and every VARCHAR(256) with VARCHAR(255) doesn't help either


The second way (using sqlite browser) isn't very helpful either.

Export the statistics database to a dump file, amarok_dump.sql


only exporting the statistics database will result in many lost information :irked: .


So, let's hack around the first way :D :

First of all let's better let amarok create the database:
  • Start Amarok
  • change to MySQL
  • close Amarok (don't play any song)

Up to this point it seems it is the second example of the MySQL HowTo :whistle: .

Now let's export the old collection:

(cd ~/.kde/share/apps/amarok && \
sqlite3 collection.db .dump > ~/amarok.sql)



Now we got the dump and the new database. Let's remove stuff we don't need (because Amarok already created the new database):

cat ~/amarok.sql | \
grep -v "BEGIN TRANSACTION;" | \
grep -v "COMMIT;" | \
grep -v "CREATE TABLE" | \
grep -v "CREATE INDEX" | \
grep -v "CREATE UNIQUE INDEX" > ~/amarok.sql



At this point everything seems to be ok: we'll only import the data, not the structure.

If you try to import the resulting amarok.sql it will fail, so let's fix that too:

cat ~/amarok.sql | \
grep -v "INSERT INTO admin" | \
perl -pe 's/INSERT INTO \"(.*)\" VALUES/INSERT INTO \1 VALUES/' > ~/amarok.sql



Nice, time to import:

cat ~/amarok.sql | mysql -u amarok -p amarok


Enter the password you set for the database at Amarok.

That's it :yes: , normally you will have all your data in your mysql database.


This is for the lazy ones who don't want to part by part :wink: :


(cd ~/.kde/share/apps/amarok && \
sqlite3 collection.db .dump | \
grep -v "BEGIN TRANSACTION;" | \
grep -v "COMMIT;" | \
grep -v "CREATE TABLE" | \
grep -v "CREATE INDEX" | \
grep -v "CREATE UNIQUE INDEX" | \
grep -v "INSERT INTO admin" | \
perl -pe 's/INSERT INTO \"(.*)\" VALUES/INSERT INTO \1 VALUES/' | \
mysql -u amarok -p amarok)



By the way, report if it really works, it hasn't worked for me because my collection.db was updated by Amarok 1.4.6 but the MySQL database was created by 1.4.4 and the version of Amarok I'm using is 1.4.4 (in other words: versions mess! :frown: ).


EDIT: I fixed a missing .db in the all-in-one command. I can confirm that it works :D By the way, if you don't use megatunes (or whatever is called that shop thingy) but you downloaded it's music database and don't want to use it, don't forget to add a grep -v "megatunes" | \. Otherwise mysql will complain about a missing databse.

Xplanet's monthly cronjob updateNO OOXML

Comments

Anonymous 27. May 2008, 06:07

personthingy writes:

That was so easy even i could do it, apart from this bit

"(cd ~/.kde/share/apps/amarok && \
sqlite3 collection.db .dump | \"

Where i got errors to the effect of WTF is "sqlite3".
"unknown command" may have been the error, i'm not sure.

The work around was to copy .kde/share/apps/amarok/collection.db to ~/collection.db and rename it to ~/amarok.sql thus replacing the original file of that name.

I then continued as above with no errors, and was able to start Amarok immediately, which was some relief after getting used to amarok taking 5 minutes to start, or pausing for five everytime i added another music file as it did under SQlite

I do seem to have lost all the lyrics text tho, nevermind.

:)

-Chris,
Running Amarok 1.4.9.1 using KDE 3.5.9
Lenny, May 11 build

Anonymous 26. June 2008, 03:09

Undead_Knight writes:

I just followed your recipe and everything worked, for one exception.

When I was adding the exported SQLite DB to MySQL, almost at the end, I got an error stating that a key was repeated. Because of this, my collection was not updated.

What I had to do was, after amarok created the Database structure for me and I closed it, I had to manually get into MySQL and delete all the contents from the Table "devices" ("delete from devices;"). After this, everything worked just fine.

What I discovered was that after amarok created the DB structure, it automatically populated the devices table with some information that was not consistent with my music collection.

Thank you for the help.


Running Amarok 1.4.9.1 using Gnome 2.22.2 and MySQL Server 5.0

Anonymous 1. December 2008, 07:23

C.Wolf writes:

I was so afraid I would be losing all of my Ratings, and have been looking everywhere for a quick fix. I just wanted to say thank you so much for this.
It works great for version 1.4.10 and it kept all my Ratings intact!
Now i can interface my twitter and websites with my MySQL db's!

You Rock!

Anonymous 8. April 2009, 04:39

Anonymous writes:

Thank you!

My collection was getting big enough that sqlite wasn't quite cutting it in the speed department. Your guide worked perfectly!

It's called "magnatune" by the way, not "megatune".

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

Type the two words displayed in the image below:


Smilies