Skip to content

Instantly share code, notes, and snippets.

@yllus
Forked from Bouke/gist:10454272
Last active February 3, 2016 20:22
Show Gist options
  • Save yllus/ec39c145f0cf016c5057 to your computer and use it in GitHub Desktop.
Save yllus/ec39c145f0cf016c5057 to your computer and use it in GitHub Desktop.
Install FreeTDS, unixODBC and pyodbc on OS X

First, install the following libraries:

$ brew install unixodbc
$ brew install freetds --with-unixodbc

FreeTDS should already work now, without configuration:

$ tsql -S [IP or hostname] -U [username] -P [password]
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> ^D

Onto unixODBC, we need to link to the driver, edit /usr/local/etc/odbcinst.ini:

[FreeTDS]
Description = TD Driver (MSSQL)
Driver = /usr/local/lib/libtdsodbc.so
Setup = /usr/local/lib/libtdsodbc.so
FileUsage = 1

The test command we're using requires configuring a DSN, so edit /usr/local/etc/odbc.ini:

[MYDSN]
Driver = FreeTDS
Server = [IP address]
Port = 1433

The configuration for your DNS might vary, you might need the TDS_Version or Servername directives. The above worked for me for SQL Server 2008 R2. Now, run the test command:

$ isql MYDSN [username] [password] -v
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL> ^D

If the test succeeded, you can continue onto installing the PHP PDO_ODBC extension for use with unixODBC:

http://php.net/manual/en/ref.pdo-odbc.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment