Skip to content

InstallingMicrosoftDriverOnDebianLinux

edharper01 edited this page Apr 4, 2017 · 4 revisions

Introduction

Oh yes, Microsoft has published its own driver for the Linux platform.

Installation of the release accompanying SQL Server 2016 (versions 13 and 13.1) is officially supported on RHEL 6, RHEL 7, Ubuntu 15.10, Ubuntu 16.04, and SUSE 12.

Installation of earlier releases was only supported on Red Hat.

Official installation notes for can be found on MSDN.

Installing the Microsoft ODBC Driver 11 for SQL Server on Linux on Debian

While version 11 of the MS driver is only targeted at Red Hat, it can be installed on Debian relatively easily. It supports a few advanced features (MARS for example) that FreeTDS doesn't, but it is closed source and it will only run on x86 (64-bit) platforms.

This page will guide you through setting up the Microsoft ODBC Driver on a Linux machine. This guide assumes a Debian-based distribution. The process may be significantly easier on Fedora. Make sure you have properly installed unixODBC before following this guide.

Downloading the driver

Download the latest Microsoft SQL Driver for Red Hat 6.

$ wget http://download.microsoft.com/download/B/C/D/BCDD264C-7517-4B7D-8159-C99FC5535680/RedHat6/msodbcsql-11.0.2270.0.tar.gz

Note: If this link doesn't work, go to http://msdn.microsoft.com/library/hh568451%28SQL.110%29.aspx and download the latest version of the driver for RedHat 6.

Extract the archive and navigate to the extracted path:

$ tar xf msodbc*
$ cd msodbc*

Resolving library dependencies

This is the difficult part. The Microsoft driver expects a RedHat system, and thus expects certain libraries to be at certain locations. Because we are trying to run this on a Debian system, we need to make some symbolic links so the Microsoft driver can find the necessary files. For more information on symbolic links, see this Wikipedia article.

To find out which drivers are still missing, enter the following command:

$ ldd lib64/libmsodbcsql-11.0.so.2270.0

You will see a whole lot of information which should look something like this:

linux-vdso.so.1 =>  (0x00007fff4a1ff000)
libcrypto.so.10 => not found
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa3ddca5000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa3dda9c000)
libssl.so.10 => not found
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007fa3dd897000)
libodbcinst.so.1 => not found
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007fa3dd5c2000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007fa3dd383000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fa3dd07b000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa3dcdf9000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa3dcbe3000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa3dc9c6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa3dc63c000)
/lib64/ld-linux-x86-64.so.2 (0x00007fa3de263000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007fa3dc413000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007fa3dc20e000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007fa3dc005000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007fa3dbe01000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fa3dbbea000)

These are the names of the libraries that the Microsoft driver needs. Look for the lines which say => not found. These are the libraries that we need to make sure can be found by the Microsoft driver.

On my system, the following libraries needed to be found:

$ ldd lib64/libmsodbcsql-11.0.so.2270.0 | grep not
libcrypto.so.10 => not found
libssl.so.10 => not found

Note: If you see libodbcinst.so.1 => not found in this list, you have not changed the LIB_VERSION yet, see the process for installing unixODBC.

To solve these errors, run:

$ cd /usr/lib/x86_64-linux-gnu
$ sudo apt-get install libssl-dev
$ sudo ln -s libssl.so.1.0.0 libssl.so.10
$ sudo ln -s libcrypto.so.1.0.0 libcrypto.so.10

Verify that all libraries are installed correctly:

$ cd PATH_OF_MSDRIVER
$ ldd lib64/libmsodbcsql-11.0.so.2270.0
linux-vdso.so.1 =>  (0x00007fff753d7000)
libcrypto.so.10 => /usr/lib/x86_64-linux-gnu/libcrypto.so.10 (0x00007f00e62ec000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f00e60e8000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f00e5edf000)
libssl.so.10 => /usr/lib/x86_64-linux-gnu/libssl.so.10 (0x00007f00e5c80000)
libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f00e5a7b000)
libodbcinst.so.1 => /usr/local/lib/libodbcinst.so.1 (0x00007f00e5863000)
libkrb5.so.3 => /usr/lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f00e558f000)
libgssapi_krb5.so.2 => /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f00e5350000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f00e5048000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f00e4dc6000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f00e4bb0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f00e4993000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f00e4609000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f00e43f2000)
/lib64/ld-linux-x86-64.so.2 (0x00007f00e6a8a000)
libk5crypto.so.3 => /usr/lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f00e41c8000)
libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f00e3fc4000)
libkrb5support.so.0 => /usr/lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f00e3dbb000)
libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f00e3bb6000)
libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f00e39a0000)

Installing the driver

If all looks okay, start the installation process:

$ sudo bash ./install.sh install --force

You will see a license agreement. If you agree to this license, press q, type YES and press enter. You should now see:

Checking for 64 bit Linux compatible OS ................................. FAILED
Checking required libs are installed ............................... NOT CHECKED
unixODBC utilities (odbc_config and odbcinst) installed ............ NOT CHECKED
unixODBC Driver Manager version 2.3.0 installed .................... NOT CHECKED
unixODBC Driver Manager configuration correct ...................... NOT CHECKED
Microsoft SQL Server ODBC Driver V1.0 for Linux already installed .. NOT CHECKED
Microsoft SQL Server ODBC Driver V1.0 for Linux files copied ................ OK
Symbolic links for bcp and sqlcmd created ................................... OK
Microsoft SQL Server ODBC Driver V1.0 for Linux registered ........... INSTALLED

This is fine.

You can now test whether the Microsoft library is correctly installed by trying to connect to a non-existing host with sqlcmd:

$ sqlcmd -S localhost

If you see this, you're fine:

Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : TCP Provider: Error code 0x274D.
Sqlcmd: Error: Microsoft ODBC Driver 11 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

The only thing that is left is letting unixODBC know about the Microsoft library. To this end, create a new text file with the following contents:

[MSSQL]
Description	= Official native client
Driver		=/usr/local/lib/libmsodbcsql-11.0.so.2270.0

I saved this as tds.driver.template2. Now run:

$ sudo odbcinst -i -d -f tds.driver.template2

You should now see:

odbcinst: Driver installed. Usage count increased to 1.
Target directory is /usr/local/etc

If you see this, you have successfully installed the Microsoft driver.

Acknowledgements

A lot of commands were taken from http://blog.afoolishmanifesto.com/archives/1855 and only slightly changed to work with the latest version of the driver released by Microsoft.