Installing SQL Server on Linux
Microsoft SQL Server is no longer exclusive to Windows; it can now be installed on Linux-based systems. In this guide, we will walk you through the steps required to install SQL Server on a Linux platform, allowing you to harness the power of SQL Server on your open-source environment.
Prerequisites
Before you begin the installation process, there are several prerequisites that must be met to ensure a successful installation of SQL Server on Linux. Here are the key requirements:
- A supported Linux distribution (e.g., Ubuntu, Red Hat, SUSE)
- A Linux server with at least 2 GB of RAM
- A dual-core processor or higher
- 1 GB of disk space for installation
- Superuser (root) privileges
Make sure that your Linux distribution is on the list of supported platforms by Microsoft, and ensure that you have administrative privileges to install and configure software on your server.
Step 1: Import the Microsoft Repository
To install SQL Server on Linux, you need to import the Microsoft SQL Server repository. This repository contains the SQL Server packages necessary for the installation.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/mssql-server-2019.list | sudo tee /etc/apt/sources.list.d/mssql-server.list
Ensure that you are using the correct repository URL for your Linux distribution. The example provided is for Ubuntu 20.04. Adjust the URL as needed.
Step 2: Install SQL Server
After importing the repository, you can proceed to install SQL Server on your Linux server. Use your package manager to download and install the SQL Server package.
sudo apt-get update
sudo apt-get install -y mssql-server
Make sure to replace “apt-get” with the appropriate package manager for your Linux distribution, such as “yum” for Red Hat-based systems or “zypper” for SUSE Linux.
Step 3: Configure SQL Server
Once SQL Server is installed, you need to configure it. During the configuration process, you’ll set the system administrator (sa) password and enable or disable the SQL Server features as needed.
sudo /opt/mssql/bin/mssql-conf setup
Follow the on-screen prompts to configure SQL Server according to your requirements. You’ll be asked to set the sa password, choose the edition, and enable or disable features like SQL Server Agent and Full-Text Search.
Step 4: Start and Enable the SQL Server Service
After configuring SQL Server, start the SQL Server service and enable it to ensure that it automatically starts when your Linux server boots up.
sudo systemctl start mssql-server
sudo systemctl enable mssql-server
Step 5: Install SQL Server Tools
To work with SQL Server on Linux, you can install SQL Server tools like sqlcmd and bcp. These tools allow you to interact with your SQL Server databases from the command line.
sudo apt-get install -y mssql-tools
After installing the tools, you can use sqlcmd to connect to your SQL Server instance and execute SQL queries.
Step 6: Verify the Installation
To ensure that SQL Server is up and running on your Linux server, you can use the mssql-conf tool to check the status of the service.
sudo /opt/mssql/bin/mssql-conf list
Review the output to confirm that the SQL Server service is active and running as expected. Additionally, you can connect to the SQL Server instance using sqlcmd to perform basic SQL operations.
Conclusion
Installing Microsoft SQL Server on a Linux-based server opens up a world of possibilities for database management in open-source environments. By following the steps outlined in this guide, you can set up SQL Server on Linux and begin working with one of the most powerful relational database management systems available.