How do I Uninstall MySQL in Ubuntu?

The purpose of MySQL in Ubuntu is to provide a robust, scalable, and reliable database management system for managing the data. Sometimes, users need to remove the older version of MySQL, free up disk space, or fix broken installations.

This post will address the step-by-step guide to uninstall MySQL on Ubuntu:

How do I Uninstall MySQL in Ubuntu?

To uninstall MySQL in Ubuntu, follow the steps mentioned below:

Step 1: Stop the MySQL Service

Before uninstalling the MySQL package, it is important to stop the MySQL service so that it is not in use during the uninstall process:

$ sudo systemctl stop mysql

Step 2: Remove the MySQL Packages

To remove the MySQL packages, utilize the “remove” option by specifying packages. It will remove the MySQL server, client, and other related packages:

$ sudo apt remove mysql-server mysql-client mysql-common

The output confirms that packages associated with MySQL have been removed.

Step 3: Remove the MySQL Configuration Files 

After removing the packages, some configuration files are left on the system. Remove these by executing the “purge” option by specifying the “mysql-server”, “mysql-client”, and “mysql-common” files:

$ sudo apt purge mysql-server mysql-client mysql-common

The output confirms that packages associated with MySQL have been removed with configuration files.

Step 4: Remove the Dependencies of MySQL 

To remove all dependencies of MYSQL from the operating system, utilize the “autoremove” option with the MySQL packages:

$ sudo apt autoremove mysql-server mysql-client mysql-common

The output confirms that the dependencies of MySQL have been removed. 

Step 5: Remove the MySQL Data Directory

By default, the MySQL data directory is located in “/var/lib/mysql/”. Remove this directory and all its contents with the “rm” command with the “rf” option:

$ sudo rm -rf /var/lib/mysql/

Step 6: Verify the Uninstallation 

Verify that MySQL has been completely removed by running the following command:

$ mysql -V

The output returns an error message indicating that the “mysql” command is not found, meaning that MySQL has been successfully uninstalled.

Conclusion

To uninstall MySQL in Ubuntu, remove the “mysql-server”, “mysql-client” and “mysql-common” packages from the system. Utilize the “purge” option to delete all configuration files of MySQL. 

This article has explained the step-by-step procedure to uninstall MYSQL from the Ubuntu operating system.

Over 500 Million Views on Our Blogs and YouTube! We’re inviting 10 businesses to partner with us and grow together. Click here to join us! ×