MsSQL on MacOs
Tags: microsoft, apple, database, macos
Published: 2024-06-20 17:08:24

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 :point_right: [Docker Desktop](https://www.docker.com/products/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
```

> → 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 <container-id> 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
```

→ [Link](https://nodejs.org/en/download/package-manager) 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>
```

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

[Azure Data Studio](https://learn.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15&tabs=redhat-install%2Credhat-uninstall)

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

→ `docker stop <container-id> ` to stop the docker container.