How to Install SQL Server on MacOS

Introduction

SQL Server is a relational database management tool developed by Microsoft. It is available on Windows, Linux, macOS, and as a Docker deployment.

In this tutorial, we will show you how to install SQL Server 2019 as a Docker deployment on macOS.

How to install SQL Server on macOS

Prerequisites

  • A system running macOS Catalina or later
  • A user with administrator-level privileges
  • Access to the terminal window

Install and Configure Docker

1. Download the Docker Community Edition installation file from the official Docker download page. Depending on your hardware, select the appropriate link in the Get Docker Desktop for Mac section to start the download.

Download Docker using the link in the Get Docker Desktop for Mac section

2. Double-click the .dmg file to start the installation process. Once this is done, drag the Docker.app icon to your Applications folder.

3. Launch Docker, then open the Docker drop-down menu by clicking the Docker icon in the menu bar.

4. Select Preferences.

Go to Docker preferences by clicking the Docker icon in the menu bar.

5. Open the Resources tab on the left side of the Preferences screen.

6. Increase the Memory value to 4.00 GB.

7. Once you are done, click Apply & Restart to confirm the new settings:

Go to Docker resources and set the memory to 4GB.

Install SQL Server on Mac

Note: The MSSQL server currently supports only Intel-based Macs. If you want to use SQL on a Mac featuring an ARM-based Apple chip, skip this section and read how to install the SQL alternative for ARM-based Macs.

Follow these steps to set up SQL Server as a Docker container:

Step 1: Download the SQL Server Image

Run the following command in the terminal window to download the image for SQL Server 2019:

sudo docker pull mcr.microsoft.com/mssql/server:2019-latest
Pull the MSSQL docker image from Microsoft's repository.

Step 2: Launch the SQL Server Image in Docker

To launch the image you downloaded in Docker, use:

docker run -d --name example_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Strong.Pwd-123' -p 1433:1433 mcr.microsoft.com/mssql/server:2019-latest

In the command above:

  • -d: Launches the docker container in daemon mode, allowing it to run in the background without a terminal window open.
  • --name: Sets a name for the Docker container. In this example, we are using example_sql_server.
  • -e 'ACCEPT_EULA=Y': Confirms you agree with the EULA (End User License Agreement) for Docker.
  • -e 'SA_PASSWORD=Strong.Pwd-123': Sets the database password. In this example, we are using "Strong.Pwd-123" as the password.
  • -p 1433:1433: Maps the container to the local port 1433.
  • mcr.microsoft.com/mssql/server:2019-latest: Selects an image file for Docker to use.

Note: If you get an error output with the message Microsoft(R) SQL Server(R) setup failed with error code 1. Please check the setup log in /var/opt/mssql/log for more information, try the launch command again with a stronger password.

Step 3: Check the SQL Server Docker Container

Check the status of the SQL Server Docker container with:

docker ps -a

If the STATUS column of the output for the container says Up, the container is running. If it reads Exited, the container is no longer running and requires troubleshooting.

Step 4: Install SQL Server Command-Line Tool

Use the following command to install sql-cli:

sudo npm install -g sql-cli

sql-cli is a command-line tool that allows you to run commands and queries for an SQL Server instance in the terminal window.

Note: Installing sql-cli with NPM requires that you have Node.js installed. If you don't, read our article on how to install Node.js on macOS.

Step 5: Connect to SQL Server

Connect to SQL Server by using the mssql command in the terminal window:

mssql -u sa -p Strong.Pwd-123

Where:

  • -u: Defines the username for connecting to the database. In this example, we are using the default username "sa".
  • -p: Defines the password for logging into the database. In this example, we are using "Strong.Pwd-123", which we selected while launching the SQL Server Docker container.

Note: For more information, check out our guide to installing SQL Server on Windows 10. We also have a guide on installing SQL Server on Linux.

Install the SQL Alternative for ARM-based Macs

Since the SQL server Docker image supports only amd64 architecture, attempting to run it on an ARM-based Mac machine results in error. However, Azure SQL Edge, a similar RDBM tool primarily designed for IoT edge deployments, can be used as a fully functional alternative.

Follow the steps below to install Azure SQL Edge.

Step 1: Pull the Docker Image

Download the Azure SQL Edge image to your system:

docker pull mcr.microsoft.com/azure-sql-edge
Pull the Azure SQL Edge image from Microsoft's repository.

Step 2: Run the Docker Container

When the image successfully downloads to your machine, run the container using the following command:

sudo docker run --cap-add SYS_PTRACE -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=Strong.Pwd-123' -p 1433:1433 --name sqledge -d mcr.microsoft.com/azure-sql-edge
Use the docker ps command to check if the container is running.

Step 3: Check the Container

Ensure that the Azure SQL Edge container is running properly:

docker ps

Step 4: Access the Container with Bash Shell

With the container running, you can connect to Azure SQL Edge by using the docker exec command:

sudo docker exec -it sqledge "bash"

Step 5: Connect to the Database

Once inside the container, connect to the database using the sqlcmd tool:

/opt/mssql-tools/bin/sqlcmd -S localhost -U SA

When prompted, enter the password you specified in step 2.

The database prompt appears. You can now use Azure SQL in the same way you would use MSSQL.

Conclusion

After following this tutorial, you should have SQL Server 2019 installed and ready to use on macOS as a Docker deployment. Alternatively, you learned how to deploy Azure SQL Edge on ARM-based Macs.

Check out our article to ensure you are following Docker security best practices.

Was this article helpful?
YesNo
Aleksandar Kovačević
With a background in both design and writing, Aleksandar Kovacevic aims to bring a fresh perspective to writing for IT, making complicated concepts easy to understand and approach.
Next you should read
How to Install SQL Express Server
February 4, 2021

SQL Server Express is a light, feature-restricted version of Microsoft's SQL Server 2019. This tutorial will guide you through the process of installing, upgrading, or uninstalling your copy of SQL Server Express 2019.
Read more
What Is a Database Server & What Is It Used For?
May 31, 2021

A database server is a machine used to store the database and to manage data access and retrieval. Read this article to learn more about database servers, how they work, and to see some examples of database servers.
Read more
SQL vs NoSQL: What's the Difference?
August 25, 2020

There are two main types of database solutions: SQL and NoSQL. In this article, you will learn the key differences between these database types.
Read more
What Is NoSQL Database? – NoSQL Explained
June 17, 2020

The article provides a detailed explanation of what a NoSQL databases is and how it differs from relational databases. It focuses on the strengths and weaknesses of the non-relational database model using many practical examples.
Read more