[unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQLServer' : file not found
Happens because the ODBC driver for SQL Server is not installed by default on Databricks clusters
To install the ODBC driver on a Databricks All-Purpose Cluster, you can run the following script directly in a notebook cell using the %sh magic command:
%sh
if ! [[ "16.04 18.04 20.04 22.04" == *"$(lsb_release -rs)"* ]];
then
echo "Ubuntu $(lsb_release -rs) is not currently supported.";
exit;
fi
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc
curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql17
sudo ACCEPT_EULA=Y apt-get install -y mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
sudo apt-get install -y unixodbc-dev
Results:
Once the script has been executed, you can confirm that the ODBC driver was installed successfully by running the following Python code in your notebook:
%sh
odbcinst -q -d -n "ODBC Driver 17 for SQL Server"
sqlcmd -?
dpkg -l | grep msodbcsql17
Results:
[ODBC Driver 17 for SQL Server] Description=Microsoft ODBC Driver 17 for SQL Server Driver=/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.10.so.6.1 UsageCount=1 bash: line 5: sqlcmd: command not found ii msodbcsql17 17.10.6.1-1 amd64 ODBC Driver for Microsoft(R) SQL Server(R)
Running the above Python code will display all ODBC drivers currently installed on the Databricks cluster.