Home Linux Uninstall MySQL Completely from Ubuntu 16/18.04

Uninstall MySQL Completely from Ubuntu 16/18.04

How to uninstall MySQL from ubuntu?

As a system administrator, sometimes you get a situation where you face the issue with the MySQL installation and you decide to reinstall. But removing only the MySQL server package doesn’t fix the issue because old settings again affect the new installation. For this need to completely remove the MySQL packages and remove all the old settings.

In this article, we will show you how to remove MySQL in Ubuntu 16.04/18.04/20.04.

Remember: Make sure you have the backup of the databases before removing MySQL and all its settings. To avoid any data loss.

– Remove MySQL from the Server.

– To remove the MySQL data directory.

– Now again install MySQL with the fresh settings.

Step 1. Remove MySQL in Ubuntu

The first step is to remove the MySQL package from the Ubuntu server. For this just run the following both commands.

sudo apt-get remove mysql-server

sudo apt-get autoremove

Step 2. Remove MySQL Data Directory

By default MySQL data directory path is /var/lib/mysql. Instead of removing MySQL data directory we will suggest you just rename this directory to keep a backup of the old settings. You can rename this directory like old_backup_mysql.

sudo mv /var/lib/mysql /var/lib/old_backup_mysql

READ: How to Take Backup and Restore the MySQL Database.

Step 3. Now Install MySQL Again

In the above steps, MySQL server packages removed. MySQL data directory also deleted/renamed. Now finally again we will install the MySQL packages.

apt-get install mysql mysql-server

This will create a new MySQL data directory under the default path i.e. /var/lib.



Read: Install MySQL 8 Version on CentOS 7


That’s it. You have learned how to uninstall MySQL from Ubuntu 16.04/18.04 and re-installed MySQL with new settings.

LEAVE A REPLY

Please enter your comment!
Please enter your name here