← Back to snippets

MSSQL Client in Kubernetes: Quick sqlcmd Reference

January 5, 2026Salih 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

FlagPurpose
-SServer name
-dDatabase
-U / -PUsername / Password
-NEncrypt connection
-CTrust server cert
-QRun query and exit

Gotcha

  • -P on 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.