By: Manvendra Singh | Last Updated: 2017-05-08 | Comments | SQL Server on Linux
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.
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.
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.
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.
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.
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.
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 126.96.36.199.
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.
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
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.
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
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.
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
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.
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.
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.
We can see above that all files have been removed.
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.
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.
Last Updated: 2017-05-08
About the author
View all my tips