It’s common for organizations of all sizes to choose Microsoft SQL Server as their preferred DBMS. SQL Server, which has previously only been offered for Windows, is now now accessible for Linux, giving businesses who choose Linux an additional platform on which to build their infrastructure. In this post, we’ll show you how to set up Microsoft SQL Server on Linux from scratch.
- Why Install SQL Server on Linux?
- Step 1: Download the Microsoft SQL Server Package for Linux
- Step 2: Run the SQL Server Installation Wizard
- Step 3: Install Additional SQL Server Tools (Optional)
- Step 4: Verify the SQL Server Installation
- Step 5: Configure SQL Server Firewall Rules
Why Install SQL Server on Linux?
Installing SQL Server on Linux may be useful for a number of reasons. Linux is often less expensive than Windows, so switching to it might help you save money there. Linux is preferred by several businesses because of its open-source nature and its adaptability. Lastly, SQL Server works well with Linux servers, which many businesses already have.
Before we can begin the process of installation, you will need to check that your computer fulfills the prerequisites outlined in the following list:
- A supported Linux distribution (such as Red Hat Enterprise Linux, Ubuntu, or SUSE Linux Enterprise)
- At least 2GB of available memory
- At least 6GB of available disk space
- An active internet connection
Step 1: Download the Microsoft SQL Server Package for Linux
The first thing you need to do in order to install SQL Server on Linux is to get the package that corresponds to your specific Linux system. Microsoft offers a repository for SQL Server packages that may be installed on your machine by executing the following instructions in the appropriate order:
sudo curl -o /etc/yum.repos.d/mssql-server.repo https://packages.microsoft.com/config/rhel/7/mssql-server-2019.repo sudo yum install -y mssql-server
For Ubuntu, you can use the following commands:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-server.list sudo apt-get update sudo apt-get install -y mssql-server
For SUSE Linux Enterprise, you can use the following commands:
sudo zypper addrepo -fc https://packages.microsoft.com/config/sles/12/mssql-server-2019.repo sudo zypper install -y mssql-server
Step 2: Run the SQL Server Installation Wizard
After you have finished downloading the SQL Server package for your Linux distribution, you can begin the installation process by entering the following line into the command prompt:
sudo /opt/mssql/bin/mssql-conf setup
This will start the installation wizard, which will walk you through the steps of configuring SQL Server while it is being installed. Over the course of the installation process, you will be required to choose a default language for the server as well as to specify a password for the SQL Server system administrator (sa) account.
Step 3: Install Additional SQL Server Tools (Optional)
Microsoft offers numerous additional tools that may be installed on Linux in addition to the main SQL Server package. These tools include the SQL Server command-line utilities and the mssql-tools package. Both of these tools are provided by Microsoft. You may install these tools by use the commands that are shown below:
sudo yum install -y mssql-tools unixODBC-devel sudo apt-get install -y mssql-tools unixODBC-dev sudo zypper install -y mssql-tools unixODBC-devel
Step 4: Verify the SQL Server Installation
Using the following command after the installation procedure has been completed will allow you to confirm that SQL Server is functioning properly.
systemctl status mssql-server --no-pager
The current status of the SQL Server service will be shown after this command is executed. If everything is functioning as it should, you should be able to see a notice stating that the service is up and operating.
active and running. If there are any issues, you can check the SQL Server error logs, which are located in the
Step 5: Configure SQL Server Firewall Rules
By default, SQL Server listens on TCP port 1433. In order to establish a connection to the SQL Server instance, you may have to adjust the settings on your firewall to permit inbound traffic on this port. The procedure for establishing firewall rules differs from one Linux distribution and firewall software to another, depending on which you’re using. The following are some examples:
For firewalld (used by CentOS, Red Hat Enterprise Linux, and Fedora), you can use the following commands to open TCP port 1433:
sudo firewall-cmd --zone=public --add-port=1433/tcp --permanent sudo firewall-cmd --reload
For ufw (used by Ubuntu), you can use the following commands to open TCP port 1433:
sudo ufw allow 1433/tcp
For iptables (used by many Linux distributions), you can use the following command to open TCP port 1433:
sudo iptables -A INPUT -p tcp --dport 1433 -j ACCEPT
We have included a comprehensive and step-by-step approach in this post that will help you install Microsoft SQL Server on Linux. You may quickly and simply set up a SQL Server instance on your Linux server if you follow the procedures that are provided in this article and use them as a reference. SQL Server is an excellent choice for handling your data, and it is a terrific alternative whether you are trying to save expenses, want to take advantage of the flexibility of Linux, or just want to use Linux.
No, SQL Server can only be installed on certain Linux distributions. Microsoft provides installation packages for several distributions, including Ubuntu, Red Hat Enterprise Linux, and SUSE Linux Enterprise Server. Check Microsoft's documentation to see which distributions are supported.
Yes, you can use SQL Server Management Studio (SSMS) to manage a SQL Server instance on Linux. However, you will need to install SSMS on a separate Windows machine and connect to the Linux instance using its IP address and port number.