How to Install SQL Server CLI or Client in PostgreSQL

Galaxy Glossary

How do I install the SQL Server command-line client (sqlcmd/mssql-cli)?

Install SQL Server command-line tools (sqlcmd/mssql-cli) locally so you can connect to SQL Server from a PostgreSQL workstation or container.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.

Description

Why install a SQL Server CLI when using PostgreSQL?

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.

Which package should I choose?

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.

How do I install on macOS with Homebrew?

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.

How do I install on Ubuntu/Debian?

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.

How do I install mssql-cli via pip?

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).

How do I verify the installation?

Run sqlcmd -? or mssql-cli --help. A usage banner confirms success. Connect to a test server to be certain.

How do I connect to an Azure SQL Database?

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.

What are common automation patterns?

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.

Best practices for secure storage of credentials?

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.

Why How to Install SQL Server CLI or Client in PostgreSQL is important

How to Install SQL Server CLI or Client in PostgreSQL Example Usage


sqlcmd -S prod-sql.company.internal -U analytics_ro -d ecommerce -Q "SELECT c.id, c.name, SUM(oi.quantity) AS items_purchased FROM Customers c JOIN Orders o ON o.customer_id=c.id JOIN OrderItems oi ON oi.order_id=o.id GROUP BY c.id, c.name ORDER BY items_purchased DESC;"

How to Install SQL Server CLI or Client in PostgreSQL Syntax


sqlcmd [-S server[,port]] [-U username] [-P password] [-d database] [-i input_file | -Q "query"] [-o output_file] [-b] [-G] [-l timeout]

mssql-cli [-S server[,port]] [-U username] [-d database] [-W] [-G] [-E] [-P password] [-Q "query"]

Example (ecommerce):
sqlcmd -S localhost -U report_user -d ecommerce -Q "SELECT id, name, price FROM Products WHERE stock < 10;"

Common Mistakes

Frequently Asked Questions (FAQs)

Does sqlcmd work on Apple Silicon?

Yes. Homebrew installs arm64 binaries. Rosetta is not required.

Can I use Windows authentication from macOS/Linux?

Only if Kerberos is configured and you pass -E. Otherwise use SQL logins or Azure AD (-G).

Is mssql-cli production-ready?

mssql-cli is community-maintained. It’s fine for local use but avoid scripting because its error handling is less predictable than sqlcmd.

Want to learn about other SQL terms?

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie
BauHealth Logo
Truvideo Logo
Welcome to the Galaxy, Guardian!
Oops! Something went wrong while submitting the form.