Install SQL Server on Linux and Create a Database

Install SQL Server on Linux and Create a Database
Techiio-author
Written by Sagar RabidasDecember 2, 2021
8 min read
SQL
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Techiio-author
Sagar Rabidas

Software Developer

In this blog, we will go through the process of installing SQL Server on Linux and Creating a Database.

Installing:-

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:

  • Open the terminal
  • Grab the public GPG keys to encrypt your sessions by typing the following line:
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -

  • Register the Microsoft SQL Server Ubuntu repository by typing the following line:
curl https://packages.microsoft.com/config/ubuntu/16.04/mssql-server.list | sudo tee /etc/apt/sources.list.d/mssql-server.list

  • Finally, install an updated SQL Server for Linux by typing the following commands:
sudo apt-get update

sudo apt-get install -y MySQL-server

blogpost

Configure Your SQL 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:

sudo /opt/mssql/bin/sqlservr-setup

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

blogpost

SQL Server for Linux Command Line Tools

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.

Connect to SQL Server

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:

blogpost

SQL Server Database Administration on Linux

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;

GO

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;

GO

We can prep our newly created database for use by entering the following lines:

USE dummydb;

GO

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);

GO

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);

GO

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.

SQL
Linux
database
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Sagar Rabidas
Software Developer
Techiio-followerTechiio-followerTechiio-followerTechiio-followerTechiio-follower
+8 more
300 Blog Posts
14 Discussion Threads
Trending Technologies
15
Software40
DevOps46
Frontend Development24
Backend Development20
Server Administration17
Linux Administration26
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance