How to Uninstall SQL Server vNext from a Linux Server

By:   |   Comments   |   Related: > SQL Server on Linux


Problem

I have written several tips about SQL Server vNext running on Linux based operating systems and in this tip I will explain how to uninstall SQL Server vNext from a Linux server.

Solution

We have gone through many tips on SQL Server vNext running on Linux. Here I will show you the steps to remove a SQL Server instance from a Linux server. Removing SQL Server from Linux is not very complex and is quite straight forward.

Removing SQL Server vNext on Linux Server

Note: Make sure to not execute this process on Production Server without getting proper approval.

Step 1

I would recommend running a full backup of all your user and system databases to keep a copy in case you need to recover the data. As SQL Server vNext is still in the CTP phase I assume you do not have anything critical running on this version, so you can skip this step if you wish. Once this version of SQL Server is released to production and you have production databases you should take full backups before proceeding.

Step 2

Connect to the Linux server using PuTTY or login to the server locally. I connected to my Linux server where SQL Server vNext is running through PuTTY as shown in the picture below.

connect to Linux Server

Step 3

This step is not necessary and is only to show you SQL Server details before uninstalling. Let's check whether SQL Server is running on this server by checking the SQL Server service. Run the below command to check the SQL Server service.

#Check SQL Server Service mssql-server
systemctl status mssql-server

We can see the SQL Server service is running fine in the screenshot below.

check sql server service

We can also check the SQL Server version which we are going to remove by using the sqlcmd utility as shown in the image below.

check sql server version using sqlcmd

There is one more way to check details for the installed SQL Server instance. We can run the "yum" command to check details of the SQL Server package mssql-server. Run the below yum command to get this information.

#Get package details of SQL Server
yum info mssql-server

We can see the version and status of this package. It is showing the installed package version is 14.0.100.187.

yum info mssql-server

We can also check the SQL Server binaries under /opt/mssql/ folder as shown in the below screenshot. We can compare this picture after removing SQL Server. The bin folder will be removed post uninstall.

ls -lrt /opt/mssql

Step 4

The next step is to start the uninstall process. We will run the "remove" command to delete the package and files under /opt/mssql/ which are shown in the above screenshot. However, this command will not affect user-generated and system database files, which are located under /var/opt/mssql.

#Run below command to remove SQL Server 
sudo yum remove mssql-server

sql server removal

Once you execute the above command, it will display the details of the mssql-server package and ask you to confirm the uninstall by typing "y" for yes and "N" for no. I entered "y" to go ahead with this removal as shown in the screenshot below.

sql server removal

Step 5

Now we can see SQL Server has been removed from this machine. We can verify it by checking the SQL Server service and bin folder under /opt/mssql path.

First check the SQL Server service by running the same command as in Step 3.

#check SQL Server service
systemctl status mssql-service

sql service status post removal

Now we can see this service is not loaded because it's not found, but the service is still showing as active. This will become inactive once we reboot the server which I will show in Step 7.

Next we can check the /opt/mssql location to check SQL Server binaries by running ls -lrt command.

ls -lrt /opt/mssql

We can see the bin folder has been removed and not in this location anymore.

You can also run the yum command to check details of the mssql-server package post uninstall by running the below command.

#execute below command to check details of mssql-server
yum info mssql-server

yum info mssql-server

If you notice in the above screenshot, the mssql-server package is shown as an available package where it was showing as installed before removing SQL Server from this machine.

Step 6

As mentioned earlier, the above removal process will not remove anything from location /var/opt/mssql/ where all system and user database files are placed. Let's check the files placed under /var/opt/mssql by running ls -lrt. You can see all files are still under /var/opt/mssql location and all database files are in /var/opt/mssql/data location.

ls -lrt /var/opt/mssql

This shows that removing SQL Server will not delete the database files. If you want to delete the database files run the below command.

#Remove SQL Server database files.
sudo rm -rf /var/opt/mssql/

Once the above command executes, check the location again to verify all files are removed.

check database files under /var/opt/mssql

We can see above that all files have been removed.

Step 7

In Step 5, it showed the SQL Server service status is not found, but the status was still running. We will reboot the server and check this service again.

Reboot the server and check SQL Server service

We can see above that the SQL Server service is not loaded and the status shows inactive (dead). If you try to connect to SQL Server using sqlcmd it will not allow you as shown in the above screenshot.

Now you are done with the SQL Server removal from Linux.

Next Steps


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Manvendra Singh Manvendra Singh has over 5 years of experience with SQL Server and has focused on Database Mirroring, Replication, Log Shipping, etc.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips



Comments For This Article

















get free sql tips
agree to terms