uninstall sql server ubuntu

How to Uninstall SQL Server in Ubuntu

SQL Server is a popular database management system. However, if you are facing performance issues with, or if you don’t need it anymore, then you may need to uninstall SQL Server from your system. In this article, we will learn how to uninstall SQL server in Ubuntu.


How to Uninstall SQL Server in Ubuntu

Here are the steps to uninstall SQL Server in Ubuntu.


1. Check SQL Server Status

Open terminal and run the following command to check SQL server status.

# sudo systemctl status mssql-server

If the output of above command shows Active: active (running) then it means SQL server is running on your system.


2. List Log and Data Files

You can run the following commands to view the content of data and log files of SQL Server.

# cd /var/opt/mssql/data 
# ls -lrt 


3. Uninstall SQL Server Service

Before you uninstall MSSQL, make sure you have taken backup of your SQL Server database. Run the following command to stop SQL Server.

$ sudo service mssql-server stop

Run the following command to uninstall SQL Server.

$ sudo apt-get remove mssql-sever

If you see any prompts during the process, enter ‘Y’ to proceed. The above command will read the package list and build dependence tree.


4. Verify Uninstallation

Run the following command to verify uninstallation.

$ sudo systemctl status mssql-server

This time you should see the following two lines in the output.

Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)


5. Remove Log & Data Files

Please note that the above uninstallation removes only the software installation files but not the log files or data files. Run the following command to remove log and data files.

$ sudo rm -rf /var/opt/mssql

In the above command -r option recursively removes subfolders & their contents. -f option ignores nonexistent arguments and removes files forcefully.

Also read:

How to Install or Upgrade Software from Unsupported Releases
Shell Script to Check if Script is Already Running
How to Check if Input Argument Exists in Shell Script
How to Check if Variable is Empty or Not in Shell Script
How to Check if File Exists in Shell Script

Leave a Reply

Your email address will not be published.