How to uninstall MySQL in Ubuntu

MySQL is one of the most popular database engines, which are used to ensure the operation of web sites and different web applications. Database MariaDB is used on many web servers and home computers. If you want to change database to another, or, for example, to install MariaDB instead of MySQL, you must first uninstall the old version.

In this article, we’ll look at how to remove MySQL on Ubuntu. I assume the program is installed from the official repositories or PPA, so we will remove it the same way.

The removal of MySQL in Ubuntu

Ubuntu MySQL has the same name of packages, this includes the mysql-server and mysql-client. If you want to remove MariaDB, the packages will be named differently: mariadb-server mariadb-client.

1. The MySQL Version

Let’s first see which version of MySQL you have installed. To do this, run:

mysql --version

Then you can view installed packages using the package Manager:

sudo apt search mysql-server

2. Deleting MySQL

Stop the database service:

sudo systemctl stop mysqld

To remove MySQL and save the settings and configuration files, use the option remove:

sudo apt remove mysql-server mysql-common mysql-server-core-* mysql-client-core-*

However, if you want to remove the database entirely, with all its configuration files, use purge:

sudo apt purge mysql-server mysql-common mysql-server-core-* mysql-client-core-*

Also you need to go to the directory /var/lib/mysql and delete from there database files if they’re no longer needed:

sudo rm-Rf /var/lib/mysql/

And delete the folder of configuration files if there:

sudo rm-Rf /etc/mysql/

Don’t forget the logs:

sudo rm-rf /var/log/mysql

Remove the user and group that you created for MySQL:

sudo deluser --remove-home mysql

sudo delgroup mysql

3. The removal of PPA

If you installed a new version of the PPA database, and the repository you no longer need, it is also desirable to remove. At the moment the official MySQL repository is installed in the style of CentOS with the help of deb package that can be downloaded from the official website. You enough to remove it:

sudo apt purge mysql-apt-config

If your repository was added in another, you can find it and delete in the folder /etc/apt/sources.list.d/. Files repositories, MySQL will contain in its name the words mysql or mariadb. In my case these files are missing:


In this small article we have understood how to remove MySQL Ubuntu using package Manager. As you can see, just remove the package is not enough, you need to delete some more files if you want to completely clean your system from unnecessary files.


(Visited 76 times, 1 visits today)