Open In App

How to Install SQL Server on MacOS?

Last Updated : 28 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to learn “How to install SQL Server Express in MacOs”. Now, before we jump to the setup part, Let’s learn about SQL Server Express. So, SQL Server Express is an open-source RDBMS database management system i.e. Relational database management system which is used to store, update, and access the data stored in different relational databases. It provides many benefits such as scalability, security, and business intelligence.

Steps to Install SQL Server in MacOS

To install SQL Server Express for your Mac, you need to follow the steps given below:-

Step 1: Installing Docker For Mac

Step 2: Installing SQL Server 2022

Step 3: Connecting to SQL Server

1. Installing Docker For Mac

Now, The first step is to download and install the Docker desktop setup for your Mac. Your system must have at least 4GB RAM and a supported version of macOS. You can download Docker manually using the Docker Application or from the command line. So, first I will show how to install it from the application and then from CLI. You can choose either way.

a. Install from Application Setup

  • Go to the official website to download the Docker Desktop file. Depending on your Mac, you can choose whether your system is integrated with an Intel Chip or with an Apple Silicon Chip. and click on the link to start the download.
Docker-Installation

Install Docker Desktop on Mac

  • After that, Click on your .dmg file to start the installation of your Docker and then drag the docker icon to Applications folder
Docker-File-Installation-in-Mac

Docker File Installation in Mac

  • Now, select and “Accept” the docker subscription agreement( It is Free for students or developers and also for small applications.)
  • Next, select “use recommendation settings” as you also need to setup a password in this or you can also customize as per your convenience on “Use advanced settings” . But I recommend to proceed with automatic configure settings.
  • finally click on “Finish“. and if it asks you for password then enter it.

b. Install from Command line Interface (CLI)

  • After installing the “.dmg” application of docker, run the following command line interface.
sudo hdiutil attach Docker.dmg
sudo /Volumes/Docker/Docker.app/Contents/MacOS/install
sudo hdiutil detach /Volumes/Docker

2. Installing SQL Server 2022

Now, Install the SQL Server 2022 for docker containers, to use SQL Server on MacOs. You just need to follow the steps given below in your command line (CLI).

  • Open the terminal and run the following command in it and If terminal asks you to enter the password for your Mac, You need to enter the password and wait till download completes.
sudo docker pull mcr.microsoft.com/mssql/server:2022-latest
install-sql-server

Install SQL Server

  • After completing the download, enter and run the following command
docker run -d --name SQL_Server_Docker -e 'ACCEPT_EULA=Y' -e DB_Password' -p 1433:1433 mcr.microsoft.com/mssql/server:2022-latest 

The above command contains certain parameters, which are defined as,

-d : It is used to launch your Docker container in daemon mode i.e. it runs on background having terminal window off. It is an Optional Parameter, If you want run Docker with its terminal window open you can leave this.

–name : It provides name to your Docker Container. This is also Optional Parameter. e.g. name is SQL_SERVER_DOCKER

-e ‘ACCEPT_EULA=Y’ : It shows that you agrees with the Docker EULA (End User License Agreement) and It is a required Parameter.

-e ‘SA_PASSWORD=DB_Password’ : It is a required Parameter that is used to set password for your database. In the above example, the database password is DB_Password.

-p 1433:1433 : It is a default port to listen connections and it is used to map your Docker container to your local port 1433.

mcr.microsoft.com/mssql/server:2022-latest : It is used to show which image to use in Docker Container.

  • After this, SQL Server should start running in your Mac and If you want to check the status of your SQL Server Docker Container, you need to enter the following command.
docker ps -a

3. Connecting to SQL Server

In order to connect to the SQL Server from Terminal or command Line of your MacOs , you need to follow the steps given below :-

  • First you need to install “sql-cli” tool which is a command-line tool by running the following command. This will allow you to run SQL Server instance queries and commands directly in Terminal.
sudo npm install -g sql-cli
  • After “sqi-cli” is installed, by using following command you can connect with your SQL server.
mssql -u sa -p DB_Password

The command consists certain parameters described as :-

-u: It is used to specify the username to connect with your database. In above example, we have used “sa” as database username.

-p: It defines the database password. In above example, we have used “DB_Password” as database password.

Finally, After successfully connecting with your SQL Server you will seen a message response as given below:

Output:

Connecting to localhost…done

sql-cli version 0.6.2

Enter “.help” for usage hints.

mssql

Now, you have successfully install and connected to SQL Server express in your Mac system.

Conclusion

In this article, You have successfully setup and installed SQL Server express in your Mac system. Now, we can use SQL Server Express for development or learning process and it is also suitable for creating small-scale applications. If you face any problem while installing just re-evaluate and make sure you have followed each and every step as described above. You can checkout more about SQL Server Express here.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads