MySQL is a powerful relational database management system. However, there may be situations where you need to uninstall it, such as when upgrading to a newer version, switching to a different database system, or troubleshooting issues. In this article, we will guide you step by step through uninstalling MySQL 8 on Ubuntu 24.04 LTS.

Prerequisites

Before you begin, ensure:

  1. You have administrative access to your Ubuntu system.
  2. MySQL 8 is installed on your system.

Step 1: Stop the MySQL Service

Before uninstalling MySQL, stop its service to ensure a clean removal process.

sudo systemctl stop mysql
  • sudo: Executes the command with administrative privileges.
  • systemctl stop mysql: Stops the MySQL service.

To confirm that the service has stopped:

sudo systemctl status mysql

The output should indicate that the service is inactive.

Step 2: Uninstall MySQL Packages

Use the apt package manager to remove MySQL.

  1. Remove the MySQL server package:
sudo apt remove --purge mysql-server mysql-client mysql-common -y
  • --purge: Removes configuration files in addition to the packages.
  • -y: Automatically confirms the removal process.
  1. Remove additional MySQL-related packages:
sudo apt autoremove -y
sudo apt autoclean
  • autoremove: Removes unnecessary dependencies.
  • autoclean: Cleans up cached package files.

Step 3: Delete MySQL Directories

Manually delete the MySQL data directories and configuration files to ensure no remnants remain on your system.

sudo rm -rf /etc/mysql /var/lib/mysql
  • /etc/mysql: Contains MySQL configuration files.
  • /var/lib/mysql: Contains MySQL data files.
  • rm -rf: Recursively deletes the specified directories. Use with caution.

Additionally, remove MySQL log files:

sudo rm -rf /var/log/mysql

Step 4: Verify Removal

To verify that MySQL has been completely uninstalled, run the following command:

mysql --version

If MySQL is uninstalled, the command will return an error or indicate that MySQL is not installed.

Step 5: Optional – Clean Up APT Sources

If you added a MySQL APT repository during installation, remove it to avoid issues with future updates:

sudo rm -rf /etc/apt/sources.list.d/mysql.list

Update the package list to reflect the changes:

sudo apt update

Conclusion

By following these steps, you have successfully uninstalled MySQL 8 from your Ubuntu 24.04 LTS system. This process ensures a clean removal of all MySQL files, configurations, and dependencies. If you plan to reinstall MySQL or use a different database system, your system is now ready.

If you have any questions or need assistance, feel free to reach out at:

Email: devopsbyrushi@gmail.com

Similar Posts

Leave a Reply

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