How To Completely Uninstall MySQL Server on Ubuntu

Install MySQL Server on Ubuntu 16.04

In this tutorial, we will show you how to completely uninstall the MySQL server on Ubuntu. For those of you who didn’t know, MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. The MySQL source code is freely available because it was originally developed as freeware. MySQL is written in C and C++ and is compatible with all major operating systems. MySQL can be used for a variety of applications but is most commonly found on Web servers.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you through the step-by-step completely remove MySQL on Ubuntu 20.04 LTS (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.

Completely Uninstall MySQL Server on Ubuntu

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade

Step 2. Backup MySQL databases.

Make sure to take a backup of your databases if possible before doing the below steps; otherwise, there will be a permanent loss. Following mysqldump the command will backup all of your databases to a single backup file:

sudo mysqldump --all-databases > all_databases.sql

Step 3. Completely Uninstall MySQL Server on Ubuntu.

The Ubuntu packages for MySQL Server start with ‘mysql-server’ and you can use ‘apt purge‘ to remove all these packages:

sudo apt purge mysql-server*

Next, remove MySQL Database files and logs using the following command below:

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

After that, run the autoremove command to uninstall all unwanted dependency packages installed by MySQL:

sudo apt autoremove

Congratulations! You have successfully uninstalled MySQL. Thanks for using this tutorial to uninstalling the MySQL server on your Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official MySQL website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!