Knowledge Base

How to properly uninstall MySQL Server on Linux

We will show you how to remove the MYSQL server and configuration file from your Ubuntu OS.

 

1. Close MySQL Server

The first step is to determine whether or not the MySQL Server is operating on our machine. Because attempting to remove it while it is currently running may result in an error.

Run the following command to verify the status of the MySQL server on your PC.

sudo systemctl status mysql

If the report indicates that MySQL Server is operating on the machine, we must stop it before proceeding. To terminate the process, use the following command:

sudo systemctl stop mysql

To see if the service has been halted, use the systemctl status mysql command. After ensuring that the program is not running, we may remove the MySQL Server without mishap. We may also remove any dependencies that were installed during the server setup process:

sudo systemctl status mysql

 

2. Uninstall MySQL Server

Removing MySQL Server packages is the next stage in the uninstallation procedure. Because all MySQL Server packages in Ubuntu begin with mysql-server, we may remove them all at once with the apt-purge command. To uninstall MySQL packages from your system, use the command below:

sudo apt purge mysql-server*

OR

May use this command to ensure that any kind of MySQL installed on your system is uninstalled.

sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*

Note: We could have deleted the MySQL package using the remove command. However, the remove command just removes/deletes the program binaries, but the purge command also deletes the application’s configuration data.

 

 

3. Uninstall MySQL Databases and Log Files

Even though we used the purge command to eliminate program binaries and configuration files, specific databases, security keys, and configuration files must be purged individually.

The configuration files that must be deleted are located in /etc/mysql. The security keys that must be deleted may be found at /var/lib/mysql.

We must ensure that these files are entirely removed. Otherwise, they will remain on your system and create problems when reinstalling MySQL Server.

Run the instructions below to see whether there are any files in the folders listed above.

Execute the following command to delete these configuration files, security keys, and database files.

sudo rm -r /etc/mysql /var/lib/mysql

If you enabled logging for MySQL Server, we would also need to erase the log files. Use the following command to erase any log files produced by MySQL Server.

sudo rm -r /var/log/mysql

 

 

4. Uninstall Dependencies

When we install MySQL Server, the package manager also installs several additional dependencies necessary to run the server. However, because we deleted the core package, MySQL Server, these dependencies are no longer required and should be uninstalled.

Dependencies like these are sometimes known as Orphaned Packages since their parent package has been deleted, and these packages are no longer helpful.

Run the following apt command to remove any such dependencies.

sudo apt autoremove

Please rate this article to help us improve our Knowledge Base.

0 0