DEV Community

Cover image for MsSQL on MacOs
Pranjal Sharma
Pranjal Sharma

Posted on

MsSQL on MacOs

MSSql database is easy to configure on a Windows System . For MacOs we need to take care of few steps to get it installed and run properly .

Lets see what all steps we need to follow β†’

01 : Download Docker

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. We would need it to run Microsoft SQL on Mac.

β†’ Check docker version
$ docker --version

β†’ Download and install docker from here πŸ‘‰ Docker Desktop

02 : Download the MS SQL Server Image to Docker

β†’ After that, you need to pull the SQL Server 2019 Linux container image from Microsoft Container Registry.

[ Make sure docker is running in background ]

$ sudo docker pull mcr.microsoft.com/mssql/server:2019-latest

β†’ Then you can run the docker images command and verify whether the docker image has been pulled successfully.

03 : Run the docker container

β†’ Command to run the docker container.

πŸ”₯ Command to run the container 
docker run -d --name sql_server_demo -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=reallyStrongPwd123' -p 1433:1433 mcr.microsoft.com/mssql/server:2019-latest

πŸ”₯ Command for M1 Chip, please try this
docker run -e "ACCEPT_EULA=1" -e "MSSQL_SA_PASSWORD=reallyStrongPwd123" -e "MSSQL_PID=Developer" -e "MSSQL_USER=SA" -p 1433:1433 -d --name=sql mcr.microsoft.com/azure-sql-edge
Enter fullscreen mode Exit fullscreen mode

β†’ Make sure to put you own password in SA_PASSWORD.
β†’ You can name your container after the --name flag.
β†’ -d flag represents the detach mode that releases the terminal after you run the above command.

β†’ Then run the docker ps command to verify whether your container has started to run

β†’ If your container stops after a few seconds it started, run docker ps -a command & > docker logs to check what’re the errors.

04 : Install the MS SQL CLI

β†’ Next, you need to install sql-cli via npm.

$ npm install -g sql-cli
OR
$ sudo npm install -g sql-cli
Enter fullscreen mode Exit fullscreen mode

β†’ Link to install npm if not present .

05 : Test the Installation by Login In

β†’ Testing the mssql integration by logging in

$ mssql -u sa -p <Your Pass word>

β†’ If correctly done : mssql> prompt will come up.

β†’ Then run select @@version to verify the connectivity.

$ mssql -u sa -p reallyStrongPwd123
Connecting to localhost...done
sql-cli version 0.6.2
Enter ".help" for usage hints.
mssql> select @@version
--------------------------------------------------------------------
Microsoft SQL Server 2019 (RTM-CU15) (KB5008996) - 15.0.4198.2 (X64)
Jan 12 2022 22:30:08
Copyright (C) 2019 Microsoft Corporation
Developer Edition (64-bit) on Linux (Ubuntu 20.04.3 LTS) <X64>
1 row(s) returned
Executed in 1 ms
mssql>
Enter fullscreen mode Exit fullscreen mode

06 : [OPTIONAL] Download and install the GUI application - Azure Data Studio

Azure Data Studio

07 : 😊 We Are Done ! Stop the services once completed with the work

β†’ docker stop <container-id> to stop the docker container.

Top comments (0)