Install SQL Server command-line tools (sqlcmd/mssql-cli) locally so you can connect to SQL Server from a PostgreSQL workstation or container.
Teams often run heterogeneous stacks. Installing sqlcmd
or mssql-cli
alongside psql
lets developers query SQL Server from the same machine that already hosts PostgreSQL tools, simplifying cross-database scripts, ETL jobs, and quick data checks.
sqlcmd
is the official Microsoft utility that ships with the ODBC driver. mssql-cli
is an open-source, Python-based REPL with auto-complete. Pick sqlcmd
for scripting and automation; choose mssql-cli
for interactive work.
Run brew tap microsoft/mssql-release
, then brew install --no-sandbox msodbcsql18 mssql-tools18
. Add /opt/homebrew/libexec/mssql-tools18/bin
to your PATH
to expose sqlcmd
and bcp
.
Import Microsoft’s GPG key, add the repository https://packages.microsoft.com/ubuntu/$(lsb_release -rs)/prod
, then sudo apt-get update && sudo apt-get install mssql-tools18 unixodbc-dev
. Accept the license prompts. Append export PATH=$PATH:/opt/mssql-tools18/bin
to ~/.bashrc
.
Create a virtual environment, then python3 -m pip install mssql-cli
. Ensure the ODBC driver is already installed (macOS: brew install msodbcsql18
, Ubuntu: sudo apt-get install msodbcsql18
).
Run sqlcmd -?
or mssql-cli --help
. A usage banner confirms success. Connect to a test server to be certain.
Use sqlcmd -S yourdb.database.windows.net -U app_user -d ecommerce -P 'StrongP@ss!'
. For MFA, omit -U/-P
and pass -G
to trigger Azure AD device login.
Embed sqlcmd -i script.sql
in CI pipelines that already run psql
migrations. Or use both CLIs inside a Bash script to copy data between PostgreSQL and SQL Server with CSV staging.
Store connection strings in environment variables or secret managers (AWS Secrets Manager, Azure Key Vault). Never hard-code passwords in shell history or SQL files.
Yes. Homebrew installs arm64 binaries. Rosetta is not required.
Only if Kerberos is configured and you pass -E
. Otherwise use SQL logins or Azure AD (-G
).
mssql-cli is community-maintained. It’s fine for local use but avoid scripting because its error handling is less predictable than sqlcmd.