Programming Blog

Jeremy Morgan

Mostly Coherent Ramblings of a Silicon Forest Software Developer

How to Install Microsoft SQL Server on Ubuntu Linux in 5 Minutes

I must admit I was surprised when I learned that Microsoft SQL Server would be availble in Linux. They’ve been pushing the open source initiative hard, but I didn’t expect something this big. Oh yeah, Visual Studio is now available for Mac as well. I just saw a pig flying by.

While MS-SQL is not open source they have made it available to run on open source platforms such as Linux and OSX, which I can imagine took a ton of work. So I decided to take advantage of this new option and try it out. It works great! It took 5 minutes to install. Here’s how you can do it too. Note that you will need a server with 3.5 gigs of RAM for this.

The first thing I always do on an Ubuntu machine is update it

1
2
sudo apt-get update
sudo apt-get upgrade

Next we need to import the public repository GPG keys

1
2
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list

Next we’ll install SQL Server.

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

"How to Install SQL Server in Linux"

Now we need to run a configuration script to set up the server:

1
sudo /opt/mssql/bin/sqlservr-setup

` It will ask if you want to start the service and if you’d like to start it on boot.

Here’s how you can check if the service is running:

1
systemctl status mssql-server

"How to Install SQL Server in Linux"

Install the MSSQL Tools for Linux

To test this out a little, install the MSSQL tools on Ubuntu.

Add in a new repository:

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

sudo apt-get update 
sudo apt-get install mssql-tools

Now, Let’s try to connect!

1
sqlcmd -S localhost -U SA -P '<YourPassword>'

You can run this command to view all your databases:

1
2
SELECT Name from sys.Databases;
GO

"How to Install SQL Server in Linux"

This should look pretty familiar to you if you’ve worked with SQL in the past.

1
2
CREATE DATABASE acmewidgets;
GO

Now we need to select that database:

1
2
USE acmewidgets;
GO

As a test. let’s create a customer table

1
2
CREATE TABLE customer (id INT, firstname NVARCHAR(50), lastname NVARCHAR(50));
GO

Now, let’s put some customers in there:

1
2
3
4
INSERT INTO customer VALUES (1, 'Lloyd', 'Christmas');
INSERT INTO customer VALUES (2, 'Harry', 'Dunn');
INSERT INTO customer VALUES (3, 'Mary', 'Swanson');
GO

Now, let’s take a look at those customers:

1
2
SELECT * FROM customer
GO

"How to Install SQL Server in Linux"

And it’s that easy! You can run SQL scripts here, or connect to it from SSMS, a traditional ASP site, or a .Net Core site/app. I’ll be doing a lot of ASP.Net core work in the coming months, so be sure to check back here.

To quit from SQL server, type in

1
QUIT

And you’re done!

I’ll be messing with this some more in the coming weeks and really putting it to the test, and I’ll share my results.

-Jeremy

I also did a YouTube tutorial for this article:




Do you like articles like this?

I’m constantly hacking on stuff and writing about happenings in the programmer world. You can subscribe to my feed here, or you can get the hacker newsletter 100% spam free!

You can also follow my projects on GitHub:

Intro to Application Pools in IIS

Application Pools in IIS can be somewhat of a mystery. Since they’re created for you automatically many times Administrators don’t give them a second thought. But understanding application pools is crucial to having a good running IIS server.

I cover this and other IIS Administration topics in my IIS Administration Fundamentals course at Pluralsight. Check it out!

Hands on IoT With the Raspberry Pi

Great news! I finally got my IoT course done! It took a long time to develop, and a lot of learning but totally worth it. This is not really a post advertising it but just a quick talk about the process.

Review: Netgear WAC730 Wireless Access Point

In this article I’ll be reviewing the Netgear Prosafe WAC730 Wireless Access Point. This is a WAP geared towards small to medium sized businesses, and is designed to compliment your existing network. I received this product for free in exchange for my honest opinion as part of the Netgear Ambassador Program. They sent me this unit to try out, and after extensive evaluation here’s what I think.

How to Set Up Free SSL for Your Website

If you’re reading this then welcome to the new server! Due to my web host taking a huge nose dive, I had to scramble to find new hosting. In doing so I explored SSL solutions and a friend suggested Let’s Encrypt. I liked the experience so much I thought I’d share it.

Easy CRUD for Your Web API With Dapper

Full disclosure here: I don’t like ORMs. If you’re building an enormous enterprise project, you should absolutely use an ORM. If you have data you really care about and a complex, monstrous system using something like Entity Framework can save you a lot of frustration. If you’re building a simple application, or some home project it’s really unnecessary.

Setting Up the Adafruit Huzzah ESP8266 Breakout

Recently I showed a friend of mine some of the projects I’ve working on with Arduino and Wifi, and he introduced me to the ESP8266 chip. I found them all over the internet ranging from $1.50 US to $20, with a variety of configurations and manufacturers. I decided to go with a company I trust, Adafruit Industries, and see what their offering is like.

Failed Request Tracing With IIS

A great tool I’ve discovered recently is the Failed Request Tracing Tool is IIS. If you’re building an ASP.Net application and having issues with requests it’s a fantastic tool. I’ll show you how to use it.