I had some requirements to do some advanced queries on my iTunes library. Searching the web I found an interesting script that I debugged and modified. This is a PHP script that will read an iTunes library file (iTunes Music Library.xml), create appropriate database tables in a MySQL database and then dump the tracks in the xml file to this database table. The script is not refined or anything but served its purpose for me. To get it up and running quickly:

  1. Make sure you’ve got PHP and MySQL installed properly. Fast track is to install MAMP.
  2. Create a database and userid/password for your new database. Give the user all privileges on this database.
  3. Fill-in the details from two in the script below.
  4. Put the script in an appropriate location (my location is MAMP\htdocs\itunes\itunes.php).
  5. Put your browser at the script and behold …. your itunes track in a database table.
  6. Use any appropriate tool to query the database (I use CocoaMySQL).

Good luck.

itunes.php script