completely uninstall mysql

How to Uninstall MySQL Completely in Ubuntu

Often database administrators need to uninstall MySQL completely in Ubuntu but are unable to do so. There are always certain files and settings left behind that get re-used when you re-install MySQL or install a different version of MySQL later. In this article, we will learn how to uninstall MySQL completely in Ubuntu.

How to Uninstall MySQL Completely in Ubuntu

Please note, when you uninstall MySQL server it will remove all your databases and configurations too. So please make sure to take a backup of important databases before you uninstall MySQL. You can take a backup of database using MySQLdump tool as shown below.

$ mysqldump -u username -ppassword database_name > /path/to/backup/file.sql

Here are the steps to uninstall MySQL completely in Ubuntu.

1. Stop MySQL Server

First step is to stop MySQL server. Open terminal and run the following command to stop MySQL server completely.

$ sudo systemctl stop mysql

2. Remove MySQL packages

Next, remove all MySQL-related packages completely.

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

If the above command does not delete all MySQL related packages, you can also try the following command.

$ sudo apt-get remove --purge mysql*

3. Remove Configuration Files

By default, MySQL’s configuration files are located at /var/lib/mysql and /etc/mysql. While uninstalling MySQL, you also need to delete these files. If you have moved them then please replace these paths with the path to your MySQL configuration file, in the command below.

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

4. (Optional) Remove Unnecessary Packages

You can optionally run the following commands to remove any unnecessary packages that were installed along with MySQL, and also to clear apt cache.

$ sudo apt autoremove

$ sudo apt autoclean

In this article, we have learnt how to uninstall MySQL completely in Ubuntu. You can use them to make sure that all MySQL related files and packages are removed from your system, so that you can install it afresh later, if you want to.

Also read:

How to View MySQL Query Locking Table
How to Group By Date on Datetime Column
How to Select By String Length in MySQL
How to Remove All Tables in MySQL
How to Skip Tables in MySQLdump

Leave a Reply

Your email address will not be published. Required fields are marked *