Like many applications, the SQL Server for Linux preview must be installed from the command line. The thought alone filled me with nervous tension, but it’s a simple process. Here’s what you do:
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
sudo apt-get update
sudo apt-get install -y MySQL-server
In this step, configuring SQL Server is as simple as creating your login credentials as a system administrator (SA). Run the configuration utility and set up a password by entering the following command:
That’s all folks! Microsoft SQL Server has been successfully installed on your Linux machine. If you want added peace of mind, you can make sure the service is running by typing the following command:
systemctl status mssql-server
The square server for Linux preview is a command-line application so you’re gonna want the right equipment to dink round in this environment. Microsoft offers a few very beneficial tools for the job, such as SQLcmd. The SQLcmd application is designed to optimize sq. Queries and simplify numerous database management tasks. As an example, it’s incredible for batching processing and different repetitive approaches in addition to simulating the weight of test databases.
Bcp is any other exciting device to be had to sq. The server is vNext ctp1 testers. Quick for bulk copy application, BCP is command-line software that helps you to reproduction large than common query jobs from a database right into a facts report and vice versa. An easy example would be importing present worker records into a desk you created with the square server. Bcp is so bendy that it can handle the ‘bulk’ of your import and export wishes.
The command-line tools are not covered with the setup, so we’ll need to install each of the SQLcmd and BCP utilities on our own. Thankfully, it’s all pretty easy. We’ll begin by repeating the primary three steps of the setup method. But if instead of installing SQL Server again in line 4, we’ll install the updated tools by entering the following commands:
sudo apt-get update
sudo apt-get install mssql-tools
Complete the installation process by accepting the License terms and proceed to the next step.
Another critical function sqlcmd performs is connecting to the database server itself, which is necessary to create databases, import data, and so forth. We can create a secure connection to SQL Server by simply opening the terminal and running sqlcmd with parameters for our username and the password we created earlier. Your command will look something like the following:
sqlcmd -S localhost -U SA
Note: You can type ‘localhost’ in place of the username and omit the password to be prompted for it in the next line, as I illustrated in the command above. I find shorter commands are easier to execute and not screw up.
Here’s where things get tricky. For some reason, Linux gives no indication that we made a successful connection to the server. Rest easy. If the terminal doesn’t throw up any errors, all systems are most likely go. You’ll know for sure if you see output that resembles the following screenshot:
Once confident I had everything up and running correctly, I decided I’d get a feel for the app by playing database administrator. Our preview has its own set of databases, so it’s perfect for this little test. To query SQL Server for a list of existing databases, enter the following lines:
SELECT Name from sys.Databases;
You’ll see that SQL Server already has a default test database available, but we’ll create our own by entering the following lines:
CREATE DATABASE dummydb;
We can prep our newly created database for use by entering the following lines:
Next we’ll create a table in our dummy database by entering the following lines:
CREATE TABLE inventory (id INT, name NVARCHAR(50), quantity INT);
Now we’ll insert data into the database by entering the following lines:
INSERT INTO inventory VALUES (1, 'pens', 170);
INSERT INTO inventory VALUES (2, 'pencils', 174);
Now that we’ve created and populated our test database, we can insert additional data, export to outside data sources, and even backup with SQLcmd.
Subscribe to get latest updates