Uninstalling MySQL from Ubuntu System: A Step-by-Step Guide
In this short tutorial we will show you how to uninstall or remove My SQL Database server engine from Ubuntu 20.04 LTS.
Introduction
MySQL is a popular open-source relational database management system used by many applications and websites. However, there may be instances where you need to remove MySQL from your Ubuntu system. This article will guide you through the process of completely uninstalling MySQL from your Ubuntu system.
Step 1: Stop the MySQL Service
The first step is to stop the MySQL service running on your Ubuntu system. Open a terminal and execute the following command:
$ sudo systemctl status mysql $ sudo systemctl stop mysql
Ouput :
ramans@dev01:~$ sudo systemctl status mysql [sudo] password for ramans: ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2023-06-22 11:22:29 WIB; 9min ago Process: 1103 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 1876 (mysqld) Status: "Server is operational" Tasks: 37 (limit: 9406) Memory: 284.0M CPU: 10.976s CGroup: /system.slice/mysql.service └─1876 /usr/sbin/mysqld Jun 22 11:22:08 dev01.bckinfo.com systemd[1]: Starting MySQL Community Server... Jun 22 11:22:29 dev01.bckinfo.com systemd[1]: Started MySQL Community Server. ramans@dev01:~$ sudo systemctl stop mysql
Step 2: Remove the MySQL Package
To remove MySQL and its associated packages, use the apt-get purge command. Open the terminal and run the following command:
$ sudo apt remove mysql-server mysql-client $ sudo apt autoremove $ sudo apt autoclean
This command will remove the MySQL server, client, and other related packages.
Output :
ramans@dev01:~$ sudo apt remove mysql-server mysql-client Reading package lists... Done Building dependency tree... Done Reading state information... Done Package 'mysql-client' is not installed, so not removed Package 'mysql-server' is not installed, so not removed The following package was automatically installed and is no longer required: libllvm13 Use 'sudo apt autoremove' to remove it. 0 upgraded, 0 newly installed, 0 to remove and 154 not upgraded.
Step 3: Delete MySQL Data and Configuration Files
MySQL stores its data and configuration files in specific directories. To remove these files, execute the following command in the terminal:
$ sudo rm -rf /etc/mysql $ sudo rm -rf /var/lib/mysql
This command will delete the MySQL configuration files and the directory containing the database files.
Output :
ramans@dev01:~$ sudo rm -rf /etc/mysql
ramans@dev01:~$ sudo rm -rf /var/lib/mysql
Step 4: Remove MySQL User and Group
Next, you’ll want to remove the MySQL user and group from your Ubuntu system. In the terminal, enter the following commands:
$ sudo deluser mysql $ sudo delgroup mysql
These commands will remove the MySQL user and group from your system.
Step 5: Clean Up Residual Files and Dependencies
To ensure a clean uninstallation, it’s recommended to remove any residual files and dependencies. Execute the following command in the terminal:
$ sudo apt-get autoremove $ sudo apt autoclean
This command will remove any unused packages and dependencies that were previously installed with MySQL.
Output :
ramans@dev01:~$ sudo apt autoremove Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages will be REMOVED: libllvm13 0 upgraded, 0 newly installed, 1 to remove and 154 not upgraded. After this operation, 99,9 MB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 286554 files and directories currently installed.) Removing libllvm13:amd64 (1:13.0.1-2ubuntu2.1) ... Processing triggers for libc-bin (2.35-0ubuntu3.1) ... ramans@dev01:~$ sudo apt autoclean Reading package lists... Done Building dependency tree... Done Reading state information... Done
Conclusion
By following these steps, you can successfully remove MySQL from your Ubuntu system. Remember to exercise caution when executing these commands, as they can have a significant impact on your system. Removing MySQL will completely delete the database and its associated files, so make sure to back up any important data before proceeding with the uninstallation process.