UPDATE: HDBC-mysql, a native driver for MySQL.
People [1, 2] seem to agree the best library for writing Haskell database programs is HDBC. HDBC has native support for PostgreSQL and SQLlte, and ODBC support for MySQL and other common databases. So, to talk to MySQL I have to get ODBC working on Linux first.
1. Installing unixODBC, MySQL driver, and HDBC
There are 3 DSNs defined in odbc.ini. We can remove the first two and only keep Default. Next, edit the Default DSN's Server and Database lines properly. You can either set the User and Password lines here, or set them in the connection program. Besides editing the ini files, we can also use the GUI program ODBCConfig from the deb package unixodbc-bin. To test our settings, we can either use the command line tool isql/iusql, or the GUI tool DataManager.
tutorial can be found from Real World Haskell. To use it well you must understand dynamic exceptions.
1. I had installed the wp-db-backup plugin which sent me an SQL file weekly. I can import this SQL into other database servers and get an exact clone. I don't like this idea since I've switched to Drupal for my blogging needs.
2. I can write a program to process this SQL file.
3. The admin only blocked accesses to my blog directory but didn't shut down my database accesses. So, basically everything is still their in the database. So I wrote a little Haskell program to talk to the MySQL server and dumped a bunch of static HTML files to the disk.Dirty and quick. The tricky thing is that I must support UTF-8, which I'm totally unfamiliar with. To support UTF-8, we extract information from the database and store it into byte vectors using ByteString instead of String. Because we want to mix ByteString's with String's, we need a way to convert between them. At first I didn't know of the Data.ByteString.Char8 module and implemented the conversions the awkward way: unpack a Bytestring into a list of Word8's, then to a list of Int's, and finally to a list of Char's. Turns out we don't need any of this.