"Fixing" a Banshee music database

NOTE: This is a bit verbose in the description, but maybe you can learn something from the process. If you just want to know how to fix the Banshee database after changing user name or moving your library to a different location, scroll down.

I recently reinstalled Ubuntu and in the process changed my user name to my more commonly used 'cybolic', however after copying the ~/.config/banshee-1 directory to my new home dir I realised that Banshee had all my music indexed by absolute path meaning that it was looking for my old home dir and so couldn't play any tracks.

To fix it I assumed I would have to do a search and replace on its database, but I needed the filetype, so a quick 'file ~/.config/banshee-1/banshee.db' later I now knew that it was in SQLite 3.x format.

Now on to a tool to do the search and replace on the database...

Ubuntu has a tool in it's repos called "sqlitebrowser", that sounded about right, so I installed it and yes, it allowed me to browse the database and perform SQL queries - just what I needed.

So, long story short, to change the location of your music files in the Banshee database, here's what you do (close Banshee first):

1sudo aptitude install sqlitebrowser
2sqlitebrowser ~/.config/banshee-1/banshee.db

Now change to the tab labelled "Execute SQL" and write something like the following:

1update CoreTracks set Uri = replace(Uri, '/home/<olduser>', '/home/<newuser>');
2update PodcastEnclosures set LocalPath = replace(LocalPath, '/home/<olduser>', '/home/<newuser>');

You are now done and can start Banshee again :)