How to install Microsoft SQL on a Mac with Apple silicon chip

How to install Microsoft SQL on a Mac with Apple silicon chip

Apple's M1, M2, and the newly released M3 chips have redefined computing performance. However, running Microsoft SQL Server, which was originally designed for x86 architecture, presents challenges on these ARM-based Macs. As of September 2024, workarounds are still necessary for Mac users.

In this article, I’ll show you how to install SQL Server on a Mac using Docker—the simplest and most reliable solution. We’ll also explore how to connect to the server using popular tools like Azure Data Studio, SSMS, and Python.


Why Use Docker?

Docker stands out for its simplicity and broad support. Although there are alternatives like Colima, Podman, or Rancher Desktop, Docker is the most accessible option for developers and data professionals, providing a quick and effective way to run SQL Server on a Mac with Apple Silicon.


Setting Up SQL Server on a Mac (M1/M2)

Step 1: Install Docker

To start, you’ll need Docker installed on your Mac. Download Docker for Mac, ensuring you choose the version that supports Apple Silicon from the official Docker website. After installation, launch Docker and make sure it’s running properly.

Docker Desktop

Step 2: Run the SQL Server Container

Next, use the following command in Terminal to pull the SQL Server image and run it in a Docker container. This command sets up the container with a strong admin password:

docker run  -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrongPassword123!' -p 1433:1433 --name sql_server_demo --platform linux/amd64  -v sql_server_volume:/var/opt/mssql -d mcr.microsoft.com/mssql/server:2022-latest        

Explanation:

  • -e 'ACCEPT_EULA=Y': Accepts Microsoft SQL Server’s license agreement.
  • -e 'SA_PASSWORD=YourStrongPassword123!': Sets the admin password. Make sure it's strong, minimum 8 characters, including uppercase, lowercase letters, a special character, and a number—otherwise, the container won’t start.
  • -p 1433:1433: Maps the container’s SQL Server port (1433) to the host.
  • --platform linux/amd64: Runs the container in x86 emulation on ARM (Apple Silicon).
  • -v sql_server_volume:/var/opt/mssql: Ensures data is saved outside the container, so it’s persistent even if the container is deleted.
  • --name sql_server_demo: Names the container for easy management.

Step 3: Verify the Container is Running

To check if the SQL Server container is running, use this command:

docker ps        

If the container is running, it will appear in the list. Additionally, you can open Docker Desktop and check the Containers tab to visually confirm the container's status.

Docker Desktop, Containers tab

Connecting to SQL Server

Now that your SQL Server container is running, the next step is to connect to it using popular tools like Azure Data Studio, SSMS, or Python


1. Connecting with Azure Data Studio (Mac)

Azure Data Studio is a free and cross-platform tool for managing SQL Server databases, and it's available for Mac. Here’s how to set it up:

Steps to connect:

  1. Download and install Azure Data Studio from the official Microsoft website.
  2. Launch Azure Data Studio and navigate to the connection window.
  3. In the connection dialog, enter the following: Server: localhost | Authentication Type: SQL Login | Username: sa | Password: YourStrongPassword123! | Port: 1433 | Trust Server Certificate: Enable this option to bypass SSL certificate issues when connecting to a local container.

Connection window


Setting up a Northwind database for further checks


Test query

2. Connecting with SQL Server Management Studio (SSMS) on Windows VM

SSMS isn’t available natively for Mac, but you can run it through a Windows Virtual Machine (VM) like Parallels Desktop, which provides a stable environment for SQL Server. Here’s how:

  1. Download and install Parallels Desktop, and set up a Windows virtual machine.
  2. Download and install SQL Server Management Studio (SSMS) on the Windows VM.
  3. In SSMS, enter the following details to connect to the SQL Server container: Server: Your Mac IP Address | Authentication: SQL Server Authentication | Login: sa | Password: YourStrongPassword123! | Trust Server Certificate: Enable this option to avoid SSL issues.

Connection window


Test query

You can use other vm (like VirtualBox/UTM) as a free alternative to Parallels, though performance and stability may vary.


3. Connecting with Python (Pandas)

If you're using Python for data analysis, you can connect directly to the SQL Server container and use Pandas for querying data. There are two options, depending on whether you're using macOS or a Windows VM. In this example - visual studio but you can use any other code editor or IDE.


Option 1: Visual Studio Code on Mac

The easiest way to connect from a Mac is by using the pytds library, which avoids the need for ODBC drivers or SQLAlchemy.

1. Use the following command in Terminal to Install the necessary Python packages (pytds and pandas):

pip install python-tds pandas        

2. Example code to connect:

import pytds
import pandas as pd

# Connect to SQL Server container
conn = pytds.connect(server='localhost', user='sa', password='YourStrongPassword123!', database='Northwind')

# Execute a query and load it into a pandas DataFrame
df = pd.read_sql('SELECT * FROM Customers', conn)

# Print the result
print(df)
        


Test query, DataFrame

Option 2: Visual Studio on Windows (Parallels Desktop)

If you're running Visual Studio on Windows in a VM, use the pyodbc library for connecting:

1. Use the following command in Terminal to Install the necessary Python packages (pyodbc and pandas):

pip install pyodbc pandas        

1. Example code to connect:

import pandas as pd
import pyodbc

# Define the connection string
conn_str = 'DRIVER=SQL Server;SERVER=YOUR MAC IP ADDRESS;DATABASE=Northwind;UID=sa;PWD=YourStrongPassword123!'

conn = pyodbc.connect(conn_str)

# Query the Customers table
df = pd.read_sql('SELECT * FROM Customers', conn)

# Display the results
print(df)
        


Test query, DataFrame

By following these steps, you can successfully set up and connect to Microsoft SQL Server running in a Docker container on your Mac with Apple Silicon. Whether you're using Azure Data Studio, SSMS on a virtual machine, or Python for data analysis, these methods will allow you to seamlessly integrate SQL Server into your development environment.

Have you tried setting up SQL Server on a Mac with Docker? Share your experience in the comments, or feel free to ask questions if you encounter any issues!


Dmitry Kryuchkov

Senior Software Developer | Golang | Java

3 周

Thank you very much! The guide is simple and helpful!

回复
Shelley Griffel

Executive | CEO | Business Development | Global Marketing | Strategy | Entrepreneur | C-Level Trusted Advisor | Result Driven | Leading Opening of an International New Market to Generate Revenue

2 个月

???? ??? ?? ?? ??????.

回复
Adam Avnon

Owner at Plan(a-z) | Leading Marketing & Business Dev. for premium brands | Ex. CEO of Y&R Israel

2 个月

???? ??? ?? ?? ??????. ??? ????? ???? ?????? ???: ?????? ????? ??? ??????? ?????? ??????, ?????? ?????? ??????,?????? ????? ????????. https://chat.whatsapp.com/IyTWnwphyc8AZAcawRTUhR

回复
Ksenia koubatski

Data Analyst | Planner

5 个月

???? ?????! ??? ????? ?? ?????, ?? ????? ????!! ??????? ???? ?? ???? ????? ??? ?? ???? ??

Konstantin B.

Computer Science student looking for a new job opportunity

5 个月

Thx for the best guide ??

要查看或添加评论,请登录

社区洞察

其他会员也浏览了