Install SQL on Linux VM

One of most interesting things last year was release of MS SQL Server for Linux. Like I said in some of my posts before, I wouldn’t have dreamt of it 5-6 years ago. But things changed very much in last few years and this is another big step Microsoft took toward OpenSource community. In this post I will take you through setting up  SQL on Linux VM on Azure. First few steps will be specific to setting up environment in Azure portal but later steps can be used on local server or local VM running Linux. I simply use Azure for setting up new VM as I don’t want to waste resources on my laptop.

So first go to Azure portal and set up your Linux VM. Go to portal, click new, select ‘Compute’ and select ‘Ubuntu Server’.

Select ‘Resource Manager’ and click ‘Create’.

Set up basic parameters and click ‘OK’.

Select size for your VM. I will choose A2_V2 standard.

For optional features, leave everything and default and click ‘OK’.

Wait for validation to pass and click ‘OK’ to start provisioning of your VM.

Before we begin installation of SQL Server, we need to set up NSG to allow traffic over port 1433. Remeber that I’m doing this only for demo as I want to connect to SQL Server from my laptop. Opening port 1433 to public is very bad idea and you shouldn’t do this unless it’s for demo as well.

Go to your VM, select ‘Network interface’ , select ‘Ubuntu’ and finally ‘Network security group’.

Select ‘Inbound security rules’ and click ‘Add’.

Enter parameters to allow traffic over port 1433.

I use Putty to connect to Linux servers and I’ll use same here. After connection to my Linux VM, I can start installation of SQL Server.

First thing to do is import public repository GPG keys so we run:

curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add –

After that we need to register MS SQL Server Ubuntu repository and next command is:

curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list

Now it’s time to start package installation. First run:

sudo apt-get update

And then:

sudo apt-get install -y mssql-server

After package installation is finished, it’s time to run configuration script:

sudo /opt/mssql/bin/sqlservr-setup

In configuration you’ll be asked to accept license terms.

Then you need to enter and confirm password for SA account. Password must be at least 8 characters long and contain 3 out of 4 rules of uppercase, lowercase, digit and special character.

Finally, you we’ll be asked if you want to start SQL Server service and if you want to enable SQL Server to start on boot.

And you’re done. Now go to SSMS and connect to your SQL instance.

You can connect with most of SSMS but you’ll need latest version if you really want to do work here.

And you have MS SQL Server running on Linux VM. Best of all is that it took me 17 minutes to set up everything here. Linux VM on Azure, SQL Server… everything from 0 and after 17 minutes I have fully functional MS SQL Server running on Ubuntu. In one of next posts I’ll write more about where to go from here and what you can do with your SQL instance on Linux.

 

Article by Mustafa Toroman

I’m System Engineer at Authority Partners. I love to test and explore new technologies. Have over 20 active MS certificates such as MCSA for Windows Server and SQL Server, MCSE Private Cloud, Data Platform, Business Intelliegence and Server Infrastracture. Lately most interested in BI and Azure solutions. MCT since 2012. From 2016 MVP for Microsoft Azure.

Leave a Reply to Anonymous Cancel reply

Your email address will not be published. Required fields are marked *