MSSQL Client in Kubernetes: Quick sqlcmd Reference
January 5, 2026•Salih Kayiplar
kubernetes
mssql
database
azure
Spin up a temporary client pod
kubectl run -i --tty --rm mssql-tools \
--image=mcr.microsoft.com/mssql-tools \
--restart=Never -n default -- bash
Connect
sqlcmd -S <server> -d <database> -U <user> -P '<password>' -N -C
List databases
sqlcmd -S myserver.database.windows.net \
-U admin -P 'Pass' \
-Q "SELECT name FROM sys.databases" -N -C
List tables
sqlcmd -S myserver.database.windows.net \
-d MyDB -U admin -P 'Pass' \
-Q "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'" -N -C
Quick query
sqlcmd -S myserver.database.windows.net \
-d MyDB -U admin -P 'Pass' \
-Q "SELECT TOP 10 * FROM dbo.Users" -N -C
Flags
| Flag | Purpose |
|---|---|
-S | Server name |
-d | Database |
-U / -P | Username / Password |
-N | Encrypt connection |
-C | Trust server cert |
-Q | Run query and exit |
Gotcha
-Pon the command line shows up in process lists — omit it and enter interactively in production- Azure SQL requires
-N(encryption), you'll get a cryptic connection error without it - If
Login timeout expired: check firewall rules, private endpoints, and that the pod network can reach the SQL server - Quote the password with single quotes if it has special chars:
-P 'p@ss!word'
Ready to scale your cloud infrastructure?
Let's discuss how CloudCops can help you build secure, scalable, and modern DevOps workflows. Schedule a free discovery call today.
Related Snippets
Zalando Postgres Operator: Backup & Restore on Azure
Complete guide to setting up WAL-G backups with Azure Blob Storage for the Zalando Postgres Operator, including restore procedures and troubleshooting.
Feb 10, 2026
kubernetes
postgresql
azure
Resize PVCs Dynamically in Kubernetes
Expand PersistentVolumeClaim storage on the fly without downtime — check, patch, verify.
Jan 10, 2026
kubernetes
storage
pvc
Kubernetes Useful Commands Cheat Sheet
Battle-tested kubectl commands for daily cluster operations — pod cleanup, version checks, network debugging, bulk patching, and more.
Feb 15, 2026
kubernetes
kubectl
bash