This article I will guide you to install mssql step by step on Ubuntu 16.04 in the most detailed way with pictures.
I. Install MSSQL In Ubuntu 16.04
First, we are going to set up the repository file. Microsoft has provided a copy of this for Ubuntu here:
We are going to use the get command to copy this file to the /etc/apt/sources.list.d directory so that we may use it with apt-get. After this, we will execute ‘apt-get update’ in order to sync the package index files with the new source that we’ve just added.
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo add-apt-repository "$(wget -qO- https://packages.microsoft.com/config/ubuntu/16.04/mssql-server-2017.list)" sudo apt-get update sudo apt-get install -y mssql-server
sudo /opt/mssql/bin/mssql-conf setup
When this tutorial was made, the 16.04 directory at https://packages.microsoft.com/ubuntu/16.04/mssql-server/ was empty, so we instead used the 16.04 files here, which seems to have worked just fine.
Since the repository file is in place, the installation is as simple as running the command below. When this tutorial was made, the total size of the package and all dependencies was 747MB.
sudo apt-get update sudo apt-get install mssql-tools unixodbc-dev
- After the installation has finished, we recommend you run the /opt/mssql/bin/sqlservr-setup bash script to finish the setup process.
- While performing our first installation attempt, we received the following error, as our virtual machine was only running with 2GB of memory.
- Make sure that you have enough memory before continuing.
- sqlservr: This program requires a machine with at least 3250 megabytes of memory.
- Microsoft(R) SQL Server(R) setup failed with error code 1.
- You’ll be able to continue after you have adequate memory available.
- This is all; Microsoft SQL Server should now be running successfully and listening for traffic on TCP port 1434.
[email protected]:~# systemctl status mssql-server [email protected]:~# netstat -antp | grep 1434
II. Connecting To MSSQL
If you’d like to connect to the server from Linux, we have to install the mssql-tools package, which comes from a different repository than the one that we just set up. You can find it here:
Now, we will be downloading a copy of the prod.list file, and we will place it in the /etc/apt/sources.list.d directory.
wget https://packages.microsoft.com/config/ubuntu/16.04/prod.list -O /etc/apt/sources.list.d/pord.list apt-get update
We may now continue with installing the mssql-tools package, as shown below:
apt-get install mssql-tools -y
After this is installed, we will be able to use the sqlcmd command to interact with the database.
To see how to run sqlcmd, just run it with the -? Option for help.
Sadly, it appears that once you specify the –P option for the password, the password needs to be provided in the command line with no option of being prompted for it later. Note that your password is going to be stored in your bash history when running the package this way.
sqlcmd -U SA -P password
In the example above, we created a test database with a table named websites and a column for domain names. We then insert a domain name and pull it back out with select, confirming both that we are able to connect and that basic SQL queries appear to be working as expected.
III. Final Thoughts
Personally, we don’t think we will ever use this over other alternatives, like MariaDB or PostgreSQL.
One more thing..
Share this tutorial with your hosting administrators and networking experts friends
[junkie-alert style=”green”] If you have any questions or feedback, feel free to comment below. [/junkie-alert]