mssql-tools is a command-line utility developed by Microsoft that provides tools for interacting with Microsoft SQL Server environments. It includes sqlcmd for executing Transact-SQL (T-SQL) queries and scripts, and bcp (Bulk Copy Program) for importing and exporting large volumes of data. These tools can be useful when you want to manage SQL Server directly from the terminal without relying on graphical interfaces.
One cool thing about mssql-tools is that it’s cross-platform. It can be installed on macOS, Linux, and Windows machines. This makes it ideal for modern development environments, especially when working with cloud-based solutions like Azure SQL Database.
In this article, we’ll look at how to install mssql-tools on a Mac and use it to connect securely to an Azure SQL Database.
Install mssql-tools
We’ll install mssql-tools via Homebrew. This is a handy little package manager that makes installing easy. If you don’t have Homebrew, you can install it by running this:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once Homebrew is installed, go ahead and install mssql-tools:
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18
That’s it. The SQL Server command line tools are now installed.
By the way, that code installs version 18. By the time you read this it’s possible that a newer version is available. You can therefore use the newer version number instead of 18. To get the latest version number (as well as installation instructions), try checking the Microsoft’s help page for installing the command line tools.
After installation, you can check that it installed OK by running the following:
sqlcmd '-?'
This should return details about the program, including its version number, as well as help on usage. If you see a different version number, it’s likely that you already had an earlier version installed outside of Homebrew.
If this happens, you can update your shell’s PATH to prioritize Homebrew binaries. For zsh, add this to your ~/.zshrc:
export PATH="/opt/homebrew/bin:$PATH"
Then reload your shell:
source ~/.zshrc
Connect and Query Your Database
Now that SQL Server command line tools have been installed, you can go ahead and connect to your database.
Here’s an example of how you might connect to an Azure SQL database that’s already been created in the Azure portal:
sqlcmd -S yourserver.database.windows.net \
-d dev-test-db \
-U 'yourusername' \
-P 'yourpassword' \
-N -C \
-Q "SELECT @@VERSION"
Replace the values with your actual values.
I enclosed the username and password in quotes here, because this prevents any special characters from messing things up. I used backslashes in order to format the command across multiple lines. You can omit these if you want to condense it to a single line.
Also, if you’re concerned about security (e.g., password in terminal history), consider omitting the password option altogether. When you do this you’ll be prompted for the password each time you connect.
If you get an error like this when you run the above command:
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Login timeout expired.
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : TCP Provider: Timeout error [258]. .
Sqlcmd: Error: Microsoft ODBC Driver 18 for SQL Server : Unable to complete login process due to delay in login response.
It could simply be that your database is currently paused. Running the above code may have awoken it from its slumber. If you jump over to your portal, you might see that it’s “Resuming” or even “Online”. Chances are it’s resuming from being paused. If this happens, wait a few seconds and run the command again.
Running the command again (once the database is online) should return something like this:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Microsoft SQL Azure (RTM) - 12.0.2000.8
Jul 3 2025 16:52:14
Copyright (C) 2025 Microsoft Corporation
(1 rows affected)
If you get a similar message it means that you successfully connected to your Azure SQL database. You can now use your SQL Server command line tools on your Mac.