How to install SQL Server on MacOS

Introduction

SQL Server is a relational database management tool developed by Microsoft. It is available on Windows, Linux, macOS, and as a Docker deployment.

In this tutorial, we will show you how to install SQL Server 2019 as a Docker deployment on macOS Catalina.

How to install SQL Server on macOS

Prerequisites

  • A system running macOS Catalina
  • A user with administrator-level privileges
  • Access to the terminal window

Install and Configure Docker

1. Download the Docker Community Edition installation file from the official Docker download page. Depending on your hardware, select the appropriate link in the Get Docker Desktop for Mac section to start the download.

Download Docker using the link in the Get Docker Desktop for Mac section

2. Double-click the .dmg file to start the installation process. Once this is done, drag the Docker.app icon to your Application folder.

3. Launch Docker, then open the Docker drop-down menu and select Preferences.

Select Preferences from the Docker drop-down menu

4. Open the Resources tab on the left side of the Preferences screen. Increase the Memory value to 4.00 GB. Once you are done, click Apply & Restart to confirm the new settings:

Increase Docker memory usage in the Resources tab of the Preferences screen

Install SQL Server on Mac

Follow these steps to set up SQL Server as a Docker container:

Note: For more information, check out our guide to installing SQL Server on Windows 10. We also have a guide on installing SQL Server on Linux.

Step 1: Download the SQL Server Image

Run the following command in the terminal window to download the image for SQL Server 2019:

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

Step 2: Launch the SQL Server Image in Docker

To launch the image you downloaded in Docker, use:

docker run -d --name example_sql_server -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=Strong.Pwd-123' -p 1433:1433 mcr.microsoft.com/mssql/server:2019-latest

In the command above:

  • -d: Launches the docker container in daemon mode, allowing it to run in the background without a terminal window open.
  • --name: Sets a name for the Docker container. In this example, we are using example_sql_server.
  • -e 'ACCEPT_EULA=Y': Confirms you agree with the EULA (End User License Agreement) for Docker.
  • -e 'SA_PASSWORD=Strong.Pwd-123': Sets the database password. In this example, we are using “Strong.Pwd-123” as the password.
  • -p 1433:1433: Maps the container to the local port 1433.
  • mcr.microsoft.com/mssql/server:2019-latest: Selects an image file for Docker to use.

Note: If you get an error output with the message Microsoft(R) SQL Server(R) setup failed with error code 1. Please check the setup log in /var/opt/mssql/log for more information, try the launch command again with a stronger password.

Step 3: Check the SQL Server Docker Container

Check the status of the SQL Server Docker container with:

docker ps -a

If the <strong>STATUS</strong> column of the output for the container says Up, the container is running. If it reads Exited, the container is no longer running and requires troubleshooting.

Step 4: Install SQL Server Command-Line Tool

Use the following command to install sql-cli:

sudo npm install -g sql-cli

sql-cli is a command-line tool that allows you to run commands and queries for an SQL Server instance in the terminal window.

Note: sql-cli requires that you have NodeJs installed. If you don’t, download it from the official NodeJS website.

Step 5: Connect to SQL Server

Connect to SQL Server by using the mssql command in the terminal window:

mssql -u sa -p Strong.Pwd-123

Where:

  • -u: Defines the username for connecting to the database. In this example, we are using the default username “sa”.
  • -p: Defines the password for logging into the database. In this example, we are using “Strong.Pwd-123”, which we selected while launching the SQL Server Docker container.

Conclusion

After following this tutorial, you should have SQL Server 2019 installed and ready to use on macOS Catalina as a Docker deployment.

Check out our article to ensure you are following Docker security best practices.

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/224393.html

(0)
上一篇 2022年1月7日
下一篇 2022年1月7日

相关推荐

发表回复

登录后才能评论