Learn how installing SQL Server 2017 on a Linux machine requires the use of the command-line terminal, rather than a graphical user interface. Review a demonstration of the process on Ubuntu.
- [Instructor] Installing SQL server 2017 on your own Linus computer will work differently than how you're probably used to installing software on a Windows machine since the entire process is completed using the command line terminal rather than a graphical user interface. I'm going to demonstrate the process using a fresh installation of Ubuntu Linux version 16.04. The process is similar on Red Hat or SUSE Linux but the command line syntax is slightly different. So you'll need to consult the documentation for your specific distribution. First we need to go ahead and open up the terminal here in Linux.
I'm going to go ahead and move this window to the center of the screen and make it a little bit wider. Now the first thing we need to do is import the public repository GPG keys from Microsoft. That will allow us to decrypt the software and insure that we're getting a valid and unaltered package. I'll do that with the command curl followed by a URL. The URL is https://packages.microsoft.com/keys/microsoft.asc.
Then we'll take the contents of that file and add it to our key ring by piping the results to apt dash key. The command will include this pipe character followed by sudo, apt dash key, space add space hyphen. I press return and it'll go ahead and download that file. It also prompts me for the password for my user account because I'm using the sudo, or super user do command, I'll go ahead and type in my password. We get the message okay so I know that that line worked. And we'll go ahead to the next step.
Next we need to register the Microsoft SQL server Ubuntu repository. Again we'll run sudo and then add dash repository. Then I'll type in a double quote, a dollar sign, and an opening parenthesis followed by the command curl and then a URL again. The URL is https://packages.microsoft.com/ config/ubuntu/16.04/mssql-server.list.
We'll finish the command with a closing parenthesis and a closing double quote. Finally we can install SQL server by running sudo apt dash get update. Followed by sudo apt dash get install dash y mssql dash server. That will go through the process of downloading the package and installing it here on our machine.
When it gets done we get this message that we need to run another command here to complete the setup of Microsoft SQL server. And basically this will just go through and add a password to our system administrator account. Let's go ahead and run that now. The command is sudo space /opt/mssql/bin/mssql-conf space setup. That'll prompt me to accept the licensing terms, I'll go ahead and type in the word yes. Then I need to enter a number that corresponds to the edition of SQL server that I want to install.
We have the options up here, one through seven. We can see that one is the evaluation edition, two is developer, three is express, and so on. I'll keep things simple and we'll just install the express edition, so I'll type in the number three and press enter. Finally we need to enter in the SQL server system administrator password. Now this isn't exactly clear but this is a brand new password that we're creating right now. Now as you type the cursor isn't going to move on the screen so just continue typing the password that you want, press enter, and then you'll have the option to confirm the password.
If both of those were typed in correctly, then it'll go through the configuration process. We finish with the line that the setup has completed successfully and SQL server is now starting. Also notice on my screen that I have a line here that says that this is an Evaluation version, that there are 125 days left in the evaluation period. And that's actually because right now at the time of this recording, we're still in the prerelease period for SQL server 2017. After general release you should be able to install the Evaluation or the Developer or the Express edition of SQL server without any evaluation periods.
In order to verify that our SQL server is actually running at this point, we'll issue the command system ctl status mssql dash server. And we can see up here on the line that says active, that SQL server is indeed active and currently running. Now at this point we're all set up and we can connect to SQL server remotely from another computer just as you would with any other SQL server instance on your network. This will allow you to use SQL server Management Studio on a Windows machine to interface with the SQL server instance here in Linux.
Now unfortunately there is no version of SQL server Management Studio for Linux yet so a graphical user interface isn't available locally. To interact with SQL server locally we need to install the command line tool SQL command. We can do that by adding in another repository. Once again we'll issue the sudo command followed by add dash apt dash repository. I'll open a double quote and a dollar sign followed by an opening parenthesis, curl, and then a different URL from before.
Https://packages.microsoft.com /config/ubuntu/16.04/prod.list. We'll finish with a closing parenthesis and a closing quotation mark. Then we'll run sudo apt dash get update again. And finally we'll install the tools. The command to do that is sudo apt dash get install dash y mssql dash tools unixodbc dash dev.
That'll bring up a window that asks me to accept a licensing term for the configuration tools. I'll just press the left arrow key on my keyboard to select yes then press enter. And once again on the licensing terms for this next product I'll press left and press enter again. That'll complete the process and install the SQL command tool in a folder called opt/mssql-tools/bin. Now to make things easier we can add that location to our path variable so that we don't need to input the full path each time we call a SQL command.
We'll do that by adding a line here to our bash profile and adding the same line to our bashrc and then we'll start using the bashrc file. Finally, we can connect to our SQL server instance by running sql command dash S, the name of our server instance which since we're on the local computer we can simply use local host dash u and the user account that we want to use. In this case, the system administrator or the SA account. I'll press enter, that'll prompt me for the password that we establish for the system administrator.
I'll go ahead and type that in and press enter. And that'll leave me with a command prompt that has changed now to just a line number. This indicates that we are now inside of our SQL server instance and we can start issuing transact SQL commands. For instance I can create a new database called KinetEcoDB. Notice that when I press enter it goes to line number two. I'll issue the command go that will go ahead and create the database and return me to line number one. Now we can see what databases exist on our server instance by writing select name from SYS.databases.
Once again on the next line I'll issue the command go and we'll see that we have these databases, master, tempdb, model, msdb, and the new KinetEco database here inside of our SQL server instance. Let's go ahead and use the KinetEco database and create a new table. Use KinetEcoDB followed by the command go will change our database context into the KinetEco database. Then we'll create a new table called employees inside there that'll be a couple of columns. One is employeeID and that'll be an integer value.
Then the first name column which will be an nvarchar 50 datatype. And finally a last name column which will also be an nvarchar 50. We'll go ahead and finish the statement with a closing parenthesis and a semicolon followed by the command go and press enter and that'll create the table. Now we can insert a record into the table and I'll simply insert a single record with the employee ID number one followed by the name Adam and the last name Wilbert.
I get the return message, one row is affected so I know that row was entered in, and now we can select everything from the table. And here are the results, I can see the employee ID field as number one, first name and last name columns include Adam and Wilbert. Finally to get out of our SQL server instance and get back to the Linux command prompt we'll simply issue the command quit. So now we've got a fully functioning SQL server installation running on an Ubuntu Linux machine. Using the command line interface to install software might be a new experience for many users used to the Windows operating system.
But after the process is complete, you can connect to the server instance from other Windows computers on your network and use the graphical tools such as Management Studio that you might be more comfortable with for day to day management and development tasks.