This post is a followup to a recent post I wrote. The issue at hand is that data are stored on a SQL server (Microsoft Server 2005 or version 9 of MS SQL Server to be exact) and that I would like to send queries from a command line interface, either from Mac OS X or a Linux system. The data queried from the server will most often be analyzed in R.

I will outline how to get all of this set up on a Mac OS X which should be similar to a Linux platform.

NOTE: Do not use the Macports version of the following packages – they are NOT needed and can be compiled from source without a problem.

First, Mac OS X comes with iODBC installed by default. However, FreeTDS is only tested on unixODBC so I’ll use this instead. I didn’t get any luck with iODBC but I didn’t give it nearly as much time as I did to get unixODBC working.

First, I recommend getting the development version since all the recent updates are included. I had issues with locale Mac OS X and TDSVER=8.0 (anything higher than version 4.2 actually) specification using FreeTDS v0.82. To do so:

The configure line is taken from here. From that same documentation, we DON’T have to register the driver with the manager or add in the data source name for system wide access. I just dealt with local (home directory) files.

Recall from the previous post that I had issues with locale and TDSVER on Mac OS X. I emailed the mailing list and it was partially fixed (tsql and freebcp doesn’t work but bsqldb and isql works) in the development version of FreeTDS for TDSVER=8.0. My ~/.freetds.conf file:

@Alex First, I left Mac OS X because of issues like this. I wouldn’t use FreeTDS from MacPorts as it is very old and not working (as with many packages in there). I think autogen isn’t working for you because you are missing some packages. You can try to post the message here and I can try to help find out which package you are missing, or you can google those message (or try to find out which command is missing) and install those missing packages.

You sir, are awesome. I’m a total noob to sql and was still able to get freetds up and running on my Mac so I could practice basic level SELECT style queries directly from this platform to the MS SQL running in a Fusion VM on it.

Francis Lukesh

May 6, 2011

If you’re on OS X, I’d recommend Homebrew. These pacakges are available and current.

Tim Lu

May 18, 2011

Thanks for this awesome tutorial. I’m using Ubuntu, but it works just the same. After much hunting around and trial and error with information from message boards and other installation guides, your short tutorial worked the first time!