Bobcares

Guide to Completely Remove MySQL from Ubuntu 20.04

by | Apr 25, 2025

Learn how to remove MySQL from Ubuntu 20.04 completely. Our MySQL Support team is here to assist you with any questions or concerns you may have.

Guide to Completely Remove MySQL from Ubuntu 20.04

Guide to Completely Remove MySQL from Ubuntu 20.04If you want to start afresh or have issues running with MySQL, completely uninstalling and reinstalling MySQL on Ubuntu 20.04 can help. This blog guides you through a thorough removal and reinstallation process, ensuring that no leftover configurations or databases interfere with the new setup.

Let’s get started!

Step 1: Completely Remove MySQL from Ubuntu

  1. To begin with, we have to stop the MySQL Service with this command:
    sudo systemctl stop mysqlCopy Code

    If your MySQL service refuses to stop or won’t start in the first place, this guide on fixing MySQL not running might help.

  2. Then, use the following command to remove the MySQL server, client, and related packages:
    sudo apt-get remove --purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*Copy Code
  3. Now, it is time to delete MySQL config files, databases, and logs with this command:
    
    sudo rm -rf /etc/mysql /var/lib/mysql
    sudo rm -rf /var/log/mysql
    Copy Code
  4. If we are doing a complete cleanup, we need to remove the MySQL user and group:
    
    sudo deluser mysql
    sudo delgroup mysql
    Copy Code
  5. Then, run this command to remove unused packages and clean the system:
    
    sudo apt-get autoremove
    sudo apt-get autoclean
    Copy Code
  6. If you prefer to back up the old files just in case:
    
    sudo mv /var/lib/mysql /var/lib/mysql_bak
    sudo mv /etc/mysql /etc/mysql_bak
    Copy Code

Step 2: Reinstall MySQL on Ubuntu 20.04

  1. First, make sure the package index is up to date:
    sudo apt-get updateCopy Code
  2. Now, reinstall the MySQL server with this command:
    sudo apt-get install mysql-serverCopy Code
  3. Then, run the security script to configure secure settings:
    sudo mysql_secure_installationCopy Code

    You can avoid common MySQL errors like MySQL error 1698 (Access denied) by properly setting root access and user privileges during this step.

  4. Now, follow the prompts given to set a root password, remove anonymous users, disallow remote root login, remove test databases and reload privilege tables.
  5. Then, make sure MySQL runs at boot and is started:
    sudo systemctl enable mysql
    sudo systemctl start mysql
    Copy Code
  6. We can verify if the MySQL service is active with this command:
    sudo systemctl status mysqlCopy Code
  7. Now, run this command to log in as the root user:
    sudo mysql -u root -pCopy Code

    At this point, enter the root password when prompted to access the MySQL shell.

Troubleshooting Tips

If you are facing installation issues, try reinstalling with:

sudo apt-get install --reinstall mysql-serverCopy Code

After reinstalling, you can clean and prune leftover files again if needed.

 

If MySQL is still not running properly or showing binding issues, check your configuration with this guide on MySQL bind-address in Ubuntu.

Still having slow queries or load issues? Learn how to fix MySQL performance problems.

FAQs

Q. Will removing MySQL delete all my databases?

A. Yes. If you run commands like `sudo rm -rf /var/lib/mysql`, all databases will be permanently deleted. Be sure to back up any important data before proceeding.

Q. What’s the difference between `remove`, `purge`, and `autoremove` in apt-get?

A. `remove` deletes the package but leaves config files. `purge` deletes both the package and its configuration files. `autoremove` cleans up packages that were installed as dependencies but are no longer needed.

Q. How can I back up my MySQL databases before uninstalling?

A. You can use `mysqldump` to export all databases:

mysqldump -u root -p --all-databases > alldb_backup.sqlCopy Code

Q. How do I check if MySQL is completely uninstalled?

A. You can run:

dpkg -l | grep mysqlCopy Code

If no packages are listed, MySQL has been removed from your system.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

LiteSpeed Cache’s Guest Mode is one of the most effective ways to boost a WordPress site’s performance.

In brief, our Support Experts demonstrated how to completely remove and reinstall MySQL on Ubuntu 20.04.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Speed issues driving customers away?
We’ve got your back!