How to Completely Remove MySQL from Ubuntu

It is fairly easy uninstall MySQL server in Ubuntu. Using the apt command we can completely remove MySQL database server, the data directory and all configuration files.

But before you remove MySQL Server, backup all of your databases, especially if this is a production server. Following mysqldump command will backup all of your databases to a single backup file.

sudo mysqldump --all-databases > all_databases.sql

Now to uninstall MySQL, run the following command.

sudo apt purge mysql-*

Confirm you want to remove /var/lib/mysql directory.

uninstall mysql ubuntu

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

sudo apt autoremove

The first command will uninstall MySQL server while the second command removes all mysql dependencies that are no longer needed.

How to Completely Remove MySQL from Ubuntu

Now we have completely removed MySQL on Ubuntu. If you want to install the most recent version of MySQL server, refer to the link below.

Install Latest MySQL Version on Ubuntu