Last Updated: February 25, 2016
·
9.272K
· datasaur

Query MS SQL Server from Linux

In the past I have used FreeTDS on Linux, or pyodbc from Python scripts. A driver released this year from Microsoft has more complete support for SQL Server 2012, and a simpler installation procedure.

This is a binary distribution for RHEL / CentOS.

Install Linux driver for SQL Server: http://www.microsoft.com/en-us/download/details.aspx?id=28160

# uninstall unixODBC if version < 2.3.0 present
sudo yum remove unixODBC 

# install unixODBC 2.3.0, ODBC driver, sqlcmd and bcp utilities
./build_dm.sh
./install.sh verify
./install.sh install 

# test connectivity
sqlcmd -S <servername> -d <dbname> -U <user_id> -P <password>-Q "select @@version" # test

sqlcmd can be used interactively, or results piped to a file or process

bcp can be used for bulk import / export

1 Response
Add your response

Installation on CentOS 5.5 was a bit more effort. As documented in the driver README, I needed to download and build unixODBC 2.3.0 myself. Even though the MS installer claimed success in doing the same, it was not sufficient for the SQL driver.

Note, it also appears that the current unixODBC 2.3.1 version is not compatible, at least with the install script.

over 1 year ago ·