Introduction
As more companies are moving towards open-source technologies, Microsoft has also made its mark in the open-source community by releasing SQL Server to run on Linux. This has created a new challenge for Linux administrators who are not familiar with MS SQL. In this article, we will explore the steps to install and run MS SQL on Linux.
Installation of MS SQL on Linux
Step 1: Add the Microsoft repository
The first step is to add the Microsoft repository to the Linux system using the below command:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
sudo add-apt-repository "$(curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)"
This command will add the Microsoft repository to the Ubuntu 16.04 system. If you are using a different Linux distribution, you can check the Microsoft documentation for the correct repository command.
Step 2: Install MS SQL Server
Once the repository is added, we can proceed to install MS SQL Server using the below command:
sudo apt-get update
sudo apt-get install -y mssql-server
This will initiate the installation process for MS SQL Server. The installation may take a few minutes to complete.
Step 3: Configure MS SQL Server
After successful installation, we need to configure MS SQL Server by running the below command:
sudo /opt/mssql/bin/mssql-conf setup
During configuration, we will be prompted to enter a password for the SA account.
Connecting to MS SQL Server
Step 1: Install mssql-tools on Linux
To connect to MS SQL server from the Linux command line, we need to install the mssql-tools package. The package can be installed using the below command:
sudo apt-get install mssql-tools
Step 2: Connect to MS SQL Server
After successful installation, we can connect to MS SQL Server using the below command:
sqlcmd -S localhost -U SA
This command will connect us to MS SQL Server using the SA user account.
Step 3: Execute commands on MS SQL Server
Once connected, we can execute SQL commands on the MS SQL Server instance. For example, we can create a database using the below command:
CREATE DATABASE TestDB;
This will create a database named TestDB on the MS SQL Server instance.
Conclusion
In conclusion, running MS SQL Server on Linux is a new challenge for Linux administrators. However, the installation and configuration process is simple and easy to follow. Once connected, we can execute SQL commands on the MS SQL Server instance using the command line tools. By following these steps, we can successfully run MS SQL Server on Linux.