How to Remove MySQL Completely from Linux System

Channel: Linux
Abstract: sudo apt remove mysql mysql-server #Ubuntu and Debian systemsIt will recreate MySQL directory under /var/lib/. Below are the commands to install My

Sometimes we face issues with MySQL installation on Linux machine. If we simply remove MySQL packages and re-install doesn’t fix the issue, in that case, old settings may still exist on the server which again affects new install. In that case first, uninstall MySQL completely from the system and erase all settings of old install. To do the same follow the below settings.

Note: Please do not use below steps if MySQL has any running databases.

Step 1 – Uninstall MySQL Packages

First, uninstall all the MySQL packages installed on your server. Use one of the followings commands as per your Linux distribution.

sudo yum remove mysql mysql-server    #CentOS and RedHat systems 
sudo apt remove mysql mysql-server    #Ubuntu and Debian systems 
sudo dnf remove mysql mysql-server    #Fedora 22+ systems 
Step 2 – Romove MySQL Directory

Now we need to remove MySQL data directory from system which by default exists at /var/lib/mysql. If you didn’t find this, It may be changed to some other place, which you can find in my.cnf file with variable datadir. Delete the /var/lib/mysql directory from the system but we prefer to rename it to keep a backup of existing files.

sudo mv /var/lib/mysql /var/lib/mysql_old_backup
sudo mv /etc/mysql /etc/mysql_old_backup
Step 3 – Install MySQL Packages Again

After removing MySQL completely, install it again using package manager, It will recreate MySQL directory under /var/lib/. Below are the commands to install MySQL from default package repositories.

sudo yum install mysql-server    #CentOS and RedHat systems 
sudo apt install mysql-server    #Ubuntu and Debian systems 
sudo dnf install mysql-server    #Fedora 22+ systems 

After completing the above steps, now you have a fresh MySQL install on your system with new settings.

Ref From: tecadmin

Related articles