How to install Microsoft SQL Server on a Macbook

datCodeGuru
3 min readJan 25, 2022

--

Download Docker for Mac — Docker is a container based technology which is essentially light-weight, that allows you to run multiple processes and applications hassle free on your operating system. Unlike virtual machines that needs an hypervisor to run, docker uses the same kernel as your operating systems. Go to https://www.docker.com/products/docker-desktop to download. Installation is very simple and you can find guides here https://docs.docker.com/desktop/mac/install/

Install SQL server — To install SQL server, open your terminal and type:

docker pull mcr.microsoft.com/mssql/server:2019-latestdocker run -d --name sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=YourStrong@Passw0rd' -p 1433:1433 -h sql_server mcr.microsoft.com/mssql/server:2019-latest
  • -d will launch the container in "detached" mode and is optional. This means that containers will run in the background and you can close the terminal window
  • --name sql_server will assign a name to the container and is optional, but recommended for easier management!
  • -e will allow you to set environment variables:
  • -h sql_server Used to explicitly set the container hostname. If you don’t specify the hostname, it defaults to the container ID, which is a randomly generated system GUID.

'ACCEPT_EULA=Y' SQL Server requires the user to accept the "End User Licence Agreement" or EULA. The Y here indicates acceptance.

-e “SA_PASSWORD=P@SSW0rd”Specify your own strong password that is at least eight characters and meets the SQL Server password requirements. Required setting for the SQL Server image.

Note: If you find your image starts but then immediately stops or you get an error such as setup failed with error code 1`, then it may be you haven’t created a strong enough password. SQL Server really means it when it requests a strong password. Ensure good length with a mixture of upper and lower case, and a mix of alphanumeric characters. For more information on password requirements take a look at the Microsoft documentation.

  • -p 1433:1433 will map the local port 1433 to port 1433 on the container. Port 1433 is the default TCP port that SQL Server will listen on. password strength.
  • mcr.microsoft.com/mssql/server:2019-latest is the image we wish to run. I have used the latest version of 2019, however, if you need a different version you can check out the Microsoft SQL Server page on Docker Hub.

To show your containers, type “docker container ls” or “docker container ls — all” or “docker ps”

To stop the container, type “docker stop sql_server”

To start the container “docker start sql_server”

To remove the container “docker rm sql_server”

To connect to SQL Server

  • docker exec -it sql_server “bash”
  • Sqlcmd isn’t in the path by default, so you have to specify the full path. Once inside the container, type /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P “P@ssw0rd”
  • If successful, you should get to a sqlcmd command prompt: 1>

To create to a database

From the sqlcmd command prompt, paste the following Transact-SQL command to create a test database:

  • CREATE DATABASE TestDB
  • SELECT Name from sys.Databases
  • GO

NOTE: GO executes the previous commands

Azure Data Studio

This is an alternative to Microsoft Sql Server Management Studio(SSMS) that is unavailable for mac users.

To Download with homebrew, type: brew install — cask azure-data-studio. Alternatively, go to https://docs.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15

References

--

--