Previous article we have covered How to Install MySQL 8.0 on Ubuntu 20.04. In this tutorial , We are going to cover How to Uninstall MySQL 8 on Ubuntu 18.04/16.04 LTS Step by Step or any Cloud Instance like Amazon EC2, Azure VM, Google Compute Engine,etc. with preinstalled MySQL 8.0 and Ubuntu 18.04/16.04.
Prerequisites
- Ubuntu 20.04 LTS System
- SSH access with sudo privileges
Uninstall MySQL packages using below command.
$ sudo apt-get remove --purge mysql-server mysql-client mysql-common
Output:
Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: mysql-client* mysql-common* mysql-community-client* mysql-community-server* mysql-server* 0 upgraded, 0 newly installed, 5 to remove and 3 not upgraded. After this operation, 43.0 MB disk space will be freed. Do you want to continue? [Y/n] : y (Reading database ... 56606 files and directories currently installed.) Removing mysql-server (8.0.18-1ubuntu18.04) ... Removing mysql-community-server (8.0.18-1ubuntu18.04) ... update-alternatives: using /etc/mysql/my.cnf.fallback to provide /etc/mysql/my.cnf (my.cnf) in auto mode Removing mysql-client (8.0.18-1ubuntu18.04) ... Removing mysql-community-client (8.0.18-1ubuntu18.04) ... Removing mysql-common (8.0.18-1ubuntu18.04) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... (Reading database ... 56548 files and directories currently installed.) Purging configuration files for mysql-community-client (8.0.18-1ubuntu18.04) ... Purging configuration files for mysql-common (8.0.18-1ubuntu18.04) ... update-alternatives: warning: alternative /etc/mysql/my.cnf.fallback (part of link group my.cnf) doesn't exist; removing from list of alternatives update-alternatives: warning: /etc/alternatives/my.cnf is dangling; it will be updated with best choice Purging configuration files for mysql-community-server (8.0.18-1ubuntu18.04) ...
It asks to remove data directories, if you want to remove, Enter on Yes button.

To remove MySQL community client core packages.
$ sudo apt-get remove mysql-community-client-core
Output:
$ sudo apt-get remove mysql-community-client-core Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils mysql-community-server-core The following packages will be REMOVED: mysql-community-client-core 0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded. After this operation, 22.1 MB disk space will be freed. Do you want to continue? [Y/n]: y (Reading database ... 56514 files and directories currently installed.) Removing mysql-community-client-core (8.0.18-1ubuntu18.04) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
To remove MySQL community Server core packages.
$ sudo apt-get remove mysql-community-server-core
Output:
Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils Use 'sudo apt autoremove' to remove them. The following packages will be REMOVED: mysql-community-server-core 0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded. After this operation, 125 MB disk space will be freed. Do you want to continue? [Y/n]: y (Reading database ... 56502 files and directories currently installed.) Removing mysql-community-server-core (8.0.18-1ubuntu18.04) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... Processing triggers for libc-bin (2.27-3ubuntu1) ...
To remove undependent packages .
$ sudo apt-get autoremove
Output:
Reading package lists... Done Building dependency tree Reading state information... Done The following packages will be REMOVED: libaio1 libmecab2 mecab-ipadic mecab-ipadic-utf8 mecab-utils 0 upgraded, 0 newly installed, 5 to remove and 3 not upgraded. After this operation, 56.4 MB disk space will be freed. Do you want to continue? [Y/n]: y (Reading database ... 56378 files and directories currently installed.) Removing libaio1:amd64 (0.3.110-5ubuntu0.1) ... Removing mecab-ipadic-utf8 (2.7.0-20070801+main-1) ... update-alternatives: using /var/lib/mecab/dic/ipadic to provide /var/lib/mecab/dic/debian (mecab-dictionary) in auto mode Removing mecab-ipadic (2.7.0-20070801+main-1) ... Removing mecab-utils (0.996-5) ... Removing libmecab2:amd64 (0.996-5) ... Processing triggers for libc-bin (2.27-3ubuntu1) ...
To clean local apt pacakges.
$ sudo apt-get autoclean
By default mysql stores MySQL data files at /var/lib/mysql location. Run below commands to remove mysql backup files if you don’t need.
$ sudo rm -rf /var/lib/mysql
Conclusion
In this article, We have covered, How to Uninstall MySQL 8 on Ubuntu 20.04 LTS Step by Step.
How to Download and Install MySQL 5.7 on Ubuntu 18.04
How to Install MySQL 8.0 on Ubuntu 18.04
Reference