How To Install Microsoft SQL Server (MS SQL) on RHEL 7 (CentOS 7) / Ubuntu 16.04

6

Microsoft has released SQL Server for Redhat Enterprise Linux and Ubuntu, and it is time to take an advantage of Microsoft SQL Server to have it in top of Linux operating system.

System Requirements

Make sure your system meets below hardware requirements.

Memory Atleast 3.25 GB
File System XFS or EXT4
Disk space Minimum 1 GB
Processor type x64-compatible only

Supported Operating Systems

  • Redhat Enterprise Linux 7.5/7.4/7.3/7.2
  • Ubuntu 16.04

Setup Repository

### CentOS 7 / RHEL 7 ###

yum -y install wget
wget https://packages.microsoft.com/config/rhel/7/mssql-server-2017.repo -O /etc/yum.repos.d/mssql-server-2017.repo

### Ubuntu 16.04 ###

sudo apt-get update
sudo apt-get install -y wget curl
wget https://packages.microsoft.com/keys/microsoft.asc
sudo apt-key add microsoft.asc
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list  | sudo tee /etc/apt/sources.list.d/mssql-server-2017.list

Install Microsoft SQL Server on Linux

### CentOS 7 / RHEL 7 ###  

yum install -y mssql-server

### Ubuntu 16.04 ###

sudo apt-get update
sudo apt-get install -y mssql-server

Setup MS SQL server.

### CentOS 7 / RHEL 7 ###  

/opt/mssql/bin/mssql-conf setup

### Ubuntu 16.04 ###

sudo /opt/mssql/bin/mssql-conf setup

While running the setup, you would be asked to choose one out of seven editions of SQL Server.

1) Evaluation (free, no production use rights, 180-day limit)
2) Developer (free, no production use rights)
3) Express (free)
4) Web (PAID)
5) Standard (PAID)
6) Enterprise (PAID)
7) Enterprise Core (PAID)
8) I bought a license through a retail sales channel and have a product key to enter.

Output:

Choose an edition of SQL Server:
  1) Evaluation (free, no production use rights, 180-day limit)
  2) Developer (free, no production use rights)
  3) Express (free)
  4) Web (PAID)
  5) Standard (PAID)
  6) Enterprise (PAID)
  7) Enterprise Core (PAID)
  8) I bought a license through a retail sales channel and have a product key to enter.

Details about editions can be found at
https://go.microsoft.com/fwlink/?LinkId=852748&clcid=0x409

Use of PAID editions of this software requires separate licensing through a
Microsoft Volume Licensing program.
By choosing a PAID edition, you are verifying that you have the appropriate
number of licenses in place to install and run this software.

Enter your edition(1-8): 1 <-- Choose SQL Edition. I chose to install Evaluation
The license terms for this product can be found in
/usr/share/doc/mssql-server or downloaded from:
https://go.microsoft.com/fwlink/?LinkId=855864&clcid=0x409

The privacy statement can be viewed at:
https://go.microsoft.com/fwlink/?LinkId=853010&clcid=0x409

Do you accept the license terms? [Yes/No]:yes <-- Accept License Terms

Enter the SQL Server system administrator password: <-- Set SQL Admin Password
Confirm the SQL Server system administrator password: <-- Confirm SQL Admin Password
Configuring SQL Server...

The licensing PID was successfully processed. The new edition is [Enterprise Evaluation Edition].
ForceFlush is enabled for this instance.
ForceFlush feature is enabled for log durability.
Created symlink from /etc/systemd/system/multi-user.target.wants/mssql-server.service to /usr/lib/systemd/system/mssql-server.service.
Setup has completed successfully. SQL Server is now starting.

Start the MS SQL Service (Optional).

### CentOS 7 / RHEL 7 ### 

systemctl start mssql-server 
systemctl enable mssql-server

### Ubuntu 16.04 ###

sudo systemctl start mssql-server
sudo systemctl enable mssql-server

Install MS SQL Server tools on Linux

Configure SQL server tools repository.

### CentOS 7 / RHEL 7 ###

wget https://packages.microsoft.com/config/rhel/7/prod.repo -O /etc/yum.repos.d/msprod.repo

### Ubuntu 16.04 ###

curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list

Install MS SQL tools (sqlcmd and bcp), and ODBC developer package.

### CentOS 7 / RHEL 7 ###

yum install -y mssql-tools unixODBC-devel

### Ubuntu 16.04 ###

sudo apt-get update 
sudo apt-get install -y mssql-tools unixodbc-dev
While installing Microsoft SQL server tools, you would need to accept License terms.

Firewall

Configure the firewall to allow 1433 port so that we can access the SQL server from external machines.

FirewallD:

firewall-cmd --permanent --add-port=1433/tcp
firewall-cmd --reload

UFW:

sudo ufw allow 8080/tcp
sudo ufw reload

Connect to MS SQL server

sqlcmd command now be found /opt/mssql-tools/bin directory. To make tools command available to shell path, run the following command.

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
source ~/.bash_profile

Once the installation is complete, connect to MS SQL server using the following command.

sqlcmd -H 127.0.0.1 -U sa

Password: 
1>

That’s All.

Further Reading

You might also like

How To Install Microsoft SQL Server (MS SQL) on RHEL 7 (CentOS 7) / Ubuntu 16.04

6