Monday, August 3, 2009

MySql setup

I was interested in setting up MySql so I could use it with a Haskell program.

General setup comments:

- Install cabal. I downloaded cabal-install-0.6.2.tar.gz. After unpackaging the archive, I ran the script bootstrap.sh. This took care of downloading and installing dependencies. I originally tried manual builds as outlined in the book Real World Haskell, appendix A, but gave up because of all the dependency errors. However, the bootstrap script may also require some manual downloading of missing components, and re-running the script.

- Install HDBC. First run 'cabal update' to obtain a list of packages available from Hackage. Then run 'cabal install hdbc'. This produced errors that needed to be fixed ( I am using Fedora 9 and HDBC 2.1.1). I followed recommendations on this bug report - http://software.complete.org/software/issues/show/164. Basically, modifications needed to be made to the hdbc package file "Database/HDBC/SqlValue.hs" and the convertible package file "Data/Convertible/Instances/Time.hs". I commented out all the instance declarations which had an error message about being a duplicate of what was found in the time-1.1.3 package. In order to make the changes above, I unpackaged the archives for the hdbc and convertible packages, made the changes to the .hs files, and then installed the packages by running 'cabal install' from within the top-level directory of the package.

- Install the driver hdbc-odbc. Running 'cabal install hdbc-odbc' produced errors about missing C libraries or headers. I installed the following:

unixODBC.i386 : A complete ODBC driver manager for Linux
unixODBC-devel.i386 : Development files for programs which will use the unixODBC library.

Commands used: 'yum install unixODBC.i386' and 'yum install unixODBC-devel.i386'.

- Apparently the above packages don't include a driver for Mysql to use with the driver manager unixODBC. So I downloaded one from Sun's website:

http://dev.mysql.com/downloads/connector/odbc/5.1.html

- Using ODBC required modifying the files odbcinst.ini and odbc.ini. These were in the directory /etc. A great resource on how ODBC works for linux and details on what is needed to get it working was found at:

http://www.easysoft.com/developer/interfaces/odbc/linux.html#what_is_odbc

and also: http://www.unixodbc.org/odbcinst.html

I used an odbcinst.ini file with these values:

[MySQL]
Driver = /usr/lib/libmyodbc5.so
UsageCount = 1

And an odbc.ini file with these values:

[MySQL-test]
Description = MySQL database test
Trace = Off
TraceFile = stderr
Driver = MySQL
Server = 127.0.0.1
Port = 3306
Option = 262144

Then I tested the ability to connect using the isql utility:

isql -v MySQL -test [mysql_username] [password]

No comments:

Post a Comment