Uninstall MySQL Server from Ubuntu Completely

This guide intends to teach you to Uninstall MySQL Server from Ubuntu Completely. You may find out that when you remove MySQL from your Ubuntu server, it doesn’t remove all the dependencies and files. So here we want to show you how you can completely remove MySQL from your Ubuntu server. Stay in touch with the rest of the article.

Steps To Uninstall MySQL Server from Ubuntu Completely

In this guide, we will use Ubuntu 22.04 as an example to show you the guide steps.

Important Note: Remember to backup all your databases before you are going to remove your MySQL server completely. For those who want to upgrade their MySQL version is necessary to do this.

Now follow the steps below to complete this guide.

Step 1 – Stop MySQL Service on Ubuntu

First, you can verify whether your MySQL service is active or not on your Ubuntu server with the command below:

sudo systemctl status mysql.service

In my case, I get the following output:

Output
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
     Active: active (running) since Sun 2023-09-03 11:14:09 UTC; 21s ago
    Process: 2180 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=e>
   Main PID: 2188 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 4575)
     Memory: 365.3M
        CPU: 1.425s
     CGroup: /system.slice/mysql.service
             └─2188 /usr/sbin/mysqld
...

If your MySQL service is active and running, you must stop it by using the command below:

sudo systemctl stop mysql

At this point, if you check your MySQL status it must be inactive:

sudo systemctl status mysql.service
Output
mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
     Active: inactive (dead) since Sun 2023-09-03 11:17:24 UTC; 35s ago
    Process: 2180 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=e>
    Process: 2188 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
   Main PID: 2188 (code=exited, status=0/SUCCESS)
     Status: "Server shutdown complete"
        CPU: 3.235s
...

Step 2 – How To Completely Delete a MySQL Server from Ubuntu?

At this point, you must remove all the MySQL server packages from your Ubuntu.

Remove MySQL Server Packages

All the server packages related to MySQL start with mysql-server. Now you can easily use the following command to remove all the MySQL server packages:

sudo apt purge mysql-server*

With the apt purge command, MySQL configuration files and binaries will be deleted. But other associated files still remain in your server such as databases and log files.

You must delete the following files to remove the MySQL completely:

  • /etc/mysql: Some MySQL Configuration files are stored in this directory.
  • /var/lib/mysql: MySQL security keys are stored in this directory.
  • /var/log/mysql: MySQL Log files are stored in this directory.

So to remove all these files, you can use the following command:

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

Remove MySQL Server Dependencies

When you install MySQL server, the default package manager of your operating system will install the required dependencies for the service. At this point, you must remove the MySQL dependencies with the command below:

sudo apt autoremove

When you are done, clean up the disk space too by using the command below:

sudo apt autoclean

Note: In some situations, your configuration files may not be deleted. So you can use this command to remove them:

sudo apt remove dbconfig-mysql

That’s it, you are done.

Conclusion

At this point, you have learned How To Completely Uninstall MySQL Server with its associated files from Ubuntu. Before you completely remove your MySQL server just remember to do your database backup that does not affect your data.

Hope you enjoy it. You may be interested in these articles too:

Fix Unknown collation utf8mb4_0900_ai_ci in MySQL

How To Disable Remote Access in MySQL Database

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular