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.
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:
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.
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:
领英推荐
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:
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)
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)
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!
Senior Software Developer | Golang | Java
3 周Thank you very much! The guide is simple and helpful!
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 个月???? ??? ?? ?? ??????.
Owner at Plan(a-z) | Leading Marketing & Business Dev. for premium brands | Ex. CEO of Y&R Israel
2 个月???? ??? ?? ?? ??????. ??? ????? ???? ?????? ???: ?????? ????? ??? ??????? ?????? ??????, ?????? ?????? ??????,?????? ????? ????????. https://chat.whatsapp.com/IyTWnwphyc8AZAcawRTUhR
Data Analyst | Planner
5 个月???? ?????! ??? ????? ?? ?????, ?? ????? ????!! ??????? ???? ?? ???? ????? ??? ?? ???? ??
Computer Science student looking for a new job opportunity
5 个月Thx for the best guide ??