In this tutorial ,I will show how to connect Microsoft SQL Server on your Mac machine .Prior to SQL Server 2017 ,If you are using Mac and you want to connect MSSql Server on Mac . You need to create windows virtual machine by using virtual-box or some other tool and then install SQL server on top of it .
But now starting from SQL server 2017 you can now install SQL Server directly on to a Linux machine. And because macOS is Unix based (and Linux is Unix based), you can run SQL Server for Linux on your Mac. The way to do this is to run SQL Server on Docker. So let’s start to connect MSSql Server on your mac machine.
1- Install Docker from here .
2- Install Azure Data Studio from here. (Azure Data Studio, a cross-platform database development tool and provide seamless database management experience, regardless of whether users are connecting to on-premise or Azure-based data platforms.)
Note – After installing docker, By default, Docker will have 2GB of memory allocated to it. SQL Server needs at least 2GB. So it’s better to increase 2GB.
Step 1– After installing docker , we can download and install SQL Server for Linux. Open a Terminal window and run the following command.
sudo docker pull mcr.microsoft.com/mssql/server:2019-latest
This downloads the latest SQL Server 2019 for Linux Docker image to your computer.
Step-2– Run the following command to launch an instance of the Docker image you just downloaded and you can set sql server name (sql1) or password .
sudo docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=XXXXXX" \-p 1433:1433 --name sql1 -h sql1 \-d mcr.microsoft.com/mssql/server:2019-latest
|-d||This optional parameter launches the .It runs in the background and doesn’t need its own Terminal window open. You can omit this parameter to have the container run in its own Terminal window.|
|–name sql1||Another optional parameter. This parameter allows you to name the container.|
|-e ‘ACCEPT_EULA=Y’||The Y shows that you agree with the EULA (End User Licence Agreement). This is required in order to have SQL Server for Linux run on your Mac.|
|-e ‘SA_PASSWORD=XXXX’||Required parameter that sets the sa database password.|
|-p 1433:1433||This maps the local port 1433 to port 1433 on the container. This is the default TCP port that SQL Server uses to listen for connections.|
|mcr.microsoft.com/mssql/server:2019-latest||This tells Docker which image to use. If you downloaded a different one, use it instead.|
Step-3– Check docker container for sql is running by using below command .
sudo docker ps -a
Step-4– Now your sql server is ready to connect but it can be connected by command line tool (sql-cli) or Azure Data Studio (GUI tool) . If you want to connect using sql-cli command line tool . You can run below command to install .
Prerequisite : Nodejs should be installed for using sql-cli
sudo npm install -g sql-cli
Step-5 – Connect MSSql server using sql-cli command line tool using below command (Make sure your docker sql container is running ).
mssql -u sa -p yourpassword
Step-6 -Now let’s try to connect with Azure Data Studio. Provide sql server name and credentials which you have setup in step-2 above.
Step-7– You should be able to connect as given below . If you are getting network related error make sure your docker container for sql server is up and running. If container is not running use below command to run container and try again to connect .
docker start Yourcontainerid