Skip to content

Instantly share code, notes, and snippets.

@dbafromthecold
Last active January 14, 2024 12:10
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dbafromthecold/5ad0b0d8ff486e412fad10f5a5a5bb72 to your computer and use it in GitHub Desktop.
Save dbafromthecold/5ad0b0d8ff486e412fad10f5a5a5bb72 to your computer and use it in GitHub Desktop.
Installing the mssql-cli on Ubuntu 22.04
#######################################################################################################
#
# How to install the mssql-cli on Ubuntu 22.04 running python 3.10
#
# This is pretty hacky so please only do this on dev/test servers
#
# The first few steps here will also get the mssql-cli working on Ubuntu 20.04 (running python 3.8)
#
#######################################################################################################
# ssh to VM
ssh dbafromthecold@XXXXXXXXXXXXX
# install docker
https://docs.docker.com/engine/install/ubuntu/
# run SQL container
docker container run -d \
--publish 1433:1433 \
--env ACCEPT_EULA=Y \
--env MSSQL_SA_PASSWORD=Testing1122 \
--name sqlcontainer1 \
mcr.microsoft.com/mssql/server:2019-CU15-ubuntu-18.04
# install pip
sudo apt install -y python3-pip
# install mssql-cli with pip
pip install mssql-cli
# add location of mssql-cli to path
export PATH=$PATH:~/.local/bin
# test connecting to SQL container
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT @@VERSION"
# view file
cat ~/.local/bin/mssql-cli
# update python to python3
sed -i 's/python/python3/g' ~/.local/bin/mssql-cli
# confirm
cat ~/.local/bin/mssql-cli
# test connecting to SQL container
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT @@VERSION"
# the connection should now work on Ubuntu 20.04
# force upgrade of cli-helpers module
# https://github.com/dbcli/mssql-cli/issues/531
pip install cli-helpers --upgrade --force
# test connecting to SQL container again
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT @@VERSION"
# remove references to ownerUri on lines 22 and 93
vim ~/.local/lib/python3.10/site-packages/mssqlcli/jsonrpc/contracts/connectionservice.py
# test connecting to SQL container again
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT @@VERSION"
# install libssl1.0.0
wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl1.0/libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
sudo dpkg -i libssl1.0.0_1.0.2n-1ubuntu5_amd64.deb
# test connecting to SQL container again
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT @@VERSION"
# remove references to owner_uri from lines 91, 93, 191
vim ~/.local/lib/python3.10/site-packages/mssqlcli/mssqlcliclient.py
# test connecting to SQL container again
mssql-cli -S localhost -U sa -P Testing1122 -Q "SELECT @@VERSION"
@ManOfAsgard
Copy link

Man u r my hero, thanks a lot!

@jgnieuwhof
Copy link

Amazing! I had a bit more python editing to do, but managed to get there.

Thank you so much 🙏

@nitish2507
Copy link

@jgnieuwhof - Could you pls help add the changes you made to make it work?

@edwin-niwaha
Copy link

Nice article

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment