ubuntu 卸载sql
We learned to install SQL Server 2019 installation on Ubuntu without a Docker Container in one of my previous articles, but we might also get a request to uninstall SQL Server running on Ubuntu as well. Both the installation and the uninstallation of SQL Server is different in Linux than of Windows OS. In windows, we can remove or uninstall any program using the add or remove programs feature. In Ubuntu, We need to run the commands in order to uninstall the programs. However, before performing uninstallation, we need to take care of the below point.
在我之前的一篇文章中,我们学会了在没有Docker容器的情况下在Ubuntu上安装SQL Server 2019安装 ,但是我们也可能会收到卸载在Ubuntu上运行SQL Server的请求。 在Linux和Windows OS中,SQL Server的安装和卸载都不同。 在Windows中,我们可以使用“添加或删除程序”功能删除或卸载任何程序。 在Ubuntu中,我们需要运行命令以卸载程序。 但是,在执行卸载之前,我们需要注意以下几点。
First, launch the virtual machine and connect to your Ubuntu server where we installed the SQL Server 2019. We will use the terminal inside the Ubuntu to run the commands. However, if you want to run the command remotely, you can use the PuTTy terminal session. In this article, we will remove Microsoft SQL Server 2019 along with repository, directories, and binary files.
首先,启动虚拟机并连接到安装了SQL Server 2019的Ubuntu服务器。我们将使用Ubuntu内部的终端来运行命令。 但是,如果要远程运行命令,则可以使用PuTTy终端会话。 在本文中,我们将删除Microsoft SQL Server 2019以及存储库,目录和二进制文件。
Check the status of the SQL Server services whether it is running or not. Run the below command to check the status.
检查SQL Server服务的状态是否正在运行。 运行以下命令以检查状态。
# sudo systemctl status mssql-server
#sudo systemctl status mssql-server
You can notice in the output that SQL Server service is active (running). You can also check the uptime of service with the active status. In the output, you can also notice the mssql-server service process id.
您可以在输出中注意到SQL Server服务处于活动状态(正在运行)。 您还可以通过活动状态检查服务的正常运行时间。 在输出中,您还可以注意到mssql-server服务进程ID。
We can also view the content of the default data and log directory in Linux SQL Server. Run the below command in a terminal window.
我们还可以在Linux SQL Server中查看默认数据和日志目录的内容。 在终端窗口中运行以下命令。
# cd /var/opt/mssql/data You can go to the directory using the cd command.
#cd / var / opt / mssql / data您可以使用cd命令转到目录。
# ls -lrt Command to list out the directory files with the owner size (in bytes) and the permissions.
#ls -lrt命令列出具有所有者大小(以字节为单位)和许可权的目录文件。
As highlighted in this screenshot, all the log file, data files of the system as well as user databases are present in this directory.
如此屏幕快照中突出显示的那样,该目录中存在所有日志文件,系统数据文件以及用户数据库。
At this point, we will assume that we have performed the full database backups (if required) and move those backup files to secure location. We should be having approvals from all stakeholders (if required) before proceeding with the next step. we need to run the below command to remove the SQL Server 2019 on Ubuntu.
此时,我们将假设我们已经执行了完整的数据库备份(如果需要),并将这些备份文件移动到安全位置。 在进行下一步之前,我们应该获得所有利益相关者的批准(如果需要)。 我们需要运行以下命令以在Ubuntu上删除SQL Server 2019。
Note: This command should be running with the root user having admin access.
注意:此命令应该在具有管理员访问权限的root用户的情况下运行。
$ sudo apt-get remove mssql-sever
$ sudo apt-get删除mssql-sever
In the above screenshot, you can see that once we execute the command, it performs the following tasks.
在上面的屏幕截图中,您可以看到,一旦我们执行了该命令,它将执行以下任务。
Once it performs the above pre-requisitive, it prepares the list of packages to remove. Here we can see that it gives the message that mssql-server package will be removed. Once we have uninstalled SQL Server, the system will free 1,289 MB of disk space. We need to give confirmation to proceed with this activity. Enter ‘Y’ to proceed. We can also cancel the process at this point and if we want to cancel running this command, enter ‘N’.
一旦执行了上述先决条件,便准备要删除的软件包列表。 在这里我们可以看到它给出了消息,即将删除mssql-server软件包。 卸载SQL Server后,系统将释放1,289 MB的磁盘空间。 我们需要确认才能继续此活动。 输入“ Y”继续。 此时我们也可以取消该过程,如果要取消运行此命令,请输入“ N”。
After you enter ‘Y’, it removes the mssql-server service.
输入“ Y”后,它将删除mssql-server服务。
We do not get any confirmation message that the mssql-server.service are removed successfully or not. This returns to the $ prompt therefore, we need to verify the status of the SQL Server using the same command we used above.
我们没有收到确认成功删除mssql-server.service的任何确认消息。 这将返回到$提示符,因此,我们需要使用与上面相同的命令来验证SQL Server的状态。
$ sudo system status mssql-server
$ sudo系统状态mssql-server
In the above screenshot, you can find the status as inactive (dead).
在上面的屏幕截图中,您可以找到状态为非活动(已死)。
Now, let us go to the default data and log file directory and see if the database files exist or not. In the below image, you can see all the files still exists. It shows that after the uninstallation of SQL Server service, it does not removes the databases files from /var/opt/mssql/data directory. We can still copy these database files or the backup files present in this directory to other location. In the next step, we will remove this directory.
现在,让我们转到默认数据和日志文件目录,看看数据库文件是否存在。 在下图中,您可以看到所有文件仍然存在。 它显示卸载SQL Server服务后,它不会从/ var / opt / mssql / data目录中删除数据库文件。 我们仍然可以将这些数据库文件或此目录中存在的备份文件复制到其他位置。 在下一步中,我们将删除此目录。
We will remove the all files and directories using the command ‘rm-rf’ with sudo access.
我们将使用具有sudo访问权限的命令'rm-rf'删除所有文件和目录。
$ sudo rm -rf /var/opt/mssql
$ sudo rm -rf / var / opt / mssql
In this command, we used the below parameters with ‘rm’:
在此命令中,我们将以下参数与“ rm”一起使用:
It also does not return any message after the removal of the directory and its content.
删除目录及其内容后,它也不返回任何消息。
Now check SQL Server binaries and database files by running below command.
现在,通过运行以下命令检查SQL Server二进制文件和数据库文件。
#sudo ls -lrt /var/opt/mssql
#sudo ls -lrt / var / opt / mssql
We can see no files or directory exists in the output because we already removed those.
我们看不到输出中不存在任何文件或目录,因为我们已经删除了这些文件或目录。
We have now removed the SQL Server 2019 services running on the Ubuntu OS.
我们现在已删除了在Ubuntu OS上运行SQL Server 2019服务。
We explored the process to uninstall SQL Server on Ubuntu in this article. You must plan the process to uninstall SQL Server properly. If you have any test instance, run these command so that you could be familiar with the commands before attempting these operations in a production environment.
我们在本文中探讨了在Ubuntu上卸载SQL Server的过程。 您必须计划该过程以正确卸载SQL Server。 如果您有任何测试实例,请运行这些命令,以便在生产环境中尝试这些操作之前熟悉这些命令。
翻译自: https://www.sqlshack.com/uninstalling-sql-server-on-ubuntu/
ubuntu 卸载sql