InternotesSharing Web Development Techniques

Blossoms

<style> td,th { font-family: sans-serif; vertical-align: top; } pre[class*="language-none"].line-numbers { padding-left: .8em; } pre[class*="language-none"].line-numbers .line-numbers-rows { display: none; } </style>

Running SQL Server on a Macintosh

SQL Server is normally to be found only on Windows environments. However, it is possible to install a working version of SQL Server on a Macintosh.


On a Macintosh, you have 2 options for running SQL Server:

  • Using a Virtual Machine (such as VirtualBox), run SQL Server Express on a Windows Virtual Machine.
  • Using Docker, run the Linux version of SQL Server.

Docker is like a light virtual machine. Unlike a full virtual machine, it sets up an environment specific to your application, but uses the host machine’s resources for operating system work.

Docker was designed to run on Linux, and MacOS is not linux. However, Docker for Macintosh also includes its own Linux virtual machine, so it still does the job.

Microsoft have released versions of SQL Sever for Linux which can be freely downloaded and used with Docker for Macintosh.

Using Docker for Macintosh

See References below for links.

  • Download & Install Docker: Get Docker for Mac (Stable)
  • Start the Docker Application
  • You will need to increase allocated memory to at least 4Gb:

    Preferences 4Gb Memory
    Docker Preferences Set Memory to 4Gb

Getting & Using SQL Server

You will need to use Terminal for the following commands. Each command is a one-liner, but some have been reproduced on multiple lines for readability.

If you really need to continue a command on another line, you should finish the previous line with a space & backslash:

very long command \
more stuff

The following commands all use Docker to do the work:

  • Get MSSQL Server

    sudo docker pull microsoft/mssql-server-linux

    To upgrade:

    sudo docker pull microsoft/mssql-server-linux:latest

Docker on Linux enables persistent storage, which is what you want if you want to keep your data from one session to the next. Unfortunately, this is not available for Docker on Macintosh.

However, there is an alternative solution, which involves creating a Data Volume. This works just as well.

  • Create a Data Volume:

    docker create -v /var/opt/mssql --name mssql-data microsoft/mssql-server-linux /bin/true

Start MSSQL Server with the Data Volume

docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=[password]' -p 1433:1433
    --volumes-from  mssql-data
    -d --name mssql-server microsoft/mssql-server-linux

Where [password] is your password.

For restarting:

docker start mssql-server

References