To have the Microsoft SQL server on your MacOS, you need to have Docker installed first. You’re basically gonna create an instance of the server on the Docker.
1. Download and Install Docker for Mac
Here’s a link to download the latest version of Docker for Mac: Install Docker Desktop on Mac
Once you download it, it’s easy to install. Open the downloaded .dmg file and drag and drop the Docker to the Applications folder. You should be instructed by the Docker installation guide.
2. Download SQL Server
The following command will download SQL server 2019 for Linux Docker image.
Run this command via terminal:
sudo docker pull mcr.microsoft.com/mssql/server:2019-latest
3. Launch the Docker
The following command will launch the Docker image we downloaded:
docker run -d --name sql_server_yc -e 'ACCEPT_EULA=Y' -e 'YC_PASSWORD=macSQL123' -p 1433:1433 mcr.microsoft.com/mssql/server:2019-latest
Breakdown of the command above:
-d: launches the Docker container in daemon mode (runs the command in the background), OPTIONAL
–name sql_server_yc: name the container, OPTIONAL
-e ‘ACCEPT_EULA=Y’: Yes(Y) to agree with the EULA (End User Licence Agreement)
-e ‘SA_PASSWORD=macSQL123’: set the database password
-p 1433:1433: maps the local port 1433 to port 1433 on the container
mcr.microsoft.com/mssql/server:2019-latest: Docker image to use
Use a stronger password if you get an error.
4. Install sql-cli
Run the following command to install the sql-cli command:
sudo npm install -g sql-cli
5. Connect to the SQL Server
mssql -u sa -p macSQL123
You should be in the mssql window now and you can run queries and perform database operations now.
6. Azure Data Studio installation
It’s way easier to see your data in tables visually rather than in terminal window. You can install Azure Data Studio install to have GUI for the SQL Server.
Here’s a link you can download Azure Data Studio from: Download and install Azure Data Studio
The installation is very simple. Unzip the downloaded file and move the file to the Applications folder.
7. Connect to SQL Server in Azure Data Studio
- Open Azure Data Studio
- Click on “New Connection”
- Add the credentials
- Server Name: localhost
- Authentication Type: SQL Login
- User name: sa
- Password: macSQL123
- Database Name: Leave it as default
- Server Group: Leave it as default
You should be connected to the localhost server now.
database install microsoft server