Developers, Developers, Developers! Maksim Sorokin IT Blog

24Apr/10Off

Haskell and MySQL

In this post I will describe how to connect and use MySQL with Haskell.

In this example we will use Ubuntu machine. We will use MySQL driver for HDBC from HackageDB.

First, we need to install MySQL server:

sudo apt-get install mysql-server

Then we need MySQL client library:

sudo apt-get install libmysqlclient-dev

Then, we install HDBC MySQL driver using Cabal:

http://hackage.haskell.org/package/HDBC-mysql

And you are ready to write some code!

module DatabaseTest where

import Database.HDBC
import Database.HDBC.MySQL

main =
   do conn <- connectMySQL defaultMySQLConnectInfo {
                  mysqlHost = "localhost",
                  mysqlDatabase = "db",
                  mysqlUser = "user",
                  mysqlPassword = "pass",
                  mysqlUnixSocket = "/var/run/mysqld/mysqld.sock" }
      quickQuery conn "INSERT INTO test VALUES (1)" []
Comments (2) Trackbacks (0)
  1. Amazing…i just start learn about Haskell, going from Visual FoxPro, is very hard the change, but i hope continue learning Haskell. thanks for this post. and, if is not much, you can’t help me with books of, Haskell and MySQL and/or SQL Server, or making Business Applications, Web Applications with Haskell. i hope your answer. thanks bro.

  2. Yeah, it is pretty hard for a newcomer. I do not know any specific books about Haskell and business or web applications. However, you can take a look on Web Frameworks page on Haskell website.


Leave a comment


Trackbacks are disabled.