- Removing MySQL 5.7 Completely [closed]
- 3 Answers 3
- Completely Uninstall MySQL Server in Ubuntu
- Backup MySQL Databases in Linux
- Remove MySQL Server in Ubuntu
- Remove MySQL Database Files and Logs
- Remove Orphaned Packages Packages
- RECOMMENDED ARTICLES
- 3 thoughts on “Completely Uninstall MySQL Server in Ubuntu”
- How To Remove MySQL Completely from Your Linux System
- Step 1: Stop MySQL Service
- Step 2: Uninstall MySQL packages
- Step 3: Remove MySQL configuration and data files
- Step 4: Verify the Removal
- Conclusion
Removing MySQL 5.7 Completely [closed]
I am trying to uninstall mysql from my ubuntu 12.04 completely. But not able to. I tried a lot of commands. But nothing is working. Can anyone help out here!
sudo apt-get remove mysql-server mysql-client mysql-common sudo apt-get autoremove
I am not able to understand what to do. I want to remove everything regarding MySQL. Whenever I am trying to locate it. I am getting that. I want everything to be removed. mysql-server, mysql-client, mysql-libraries and even configuration. Please help me.
3 Answers 3
First of all, do a backup of your needed databases with mysqldump
Note: If you want to restore later, just backup your relevant databases, and not the WHOLE, because the whole database might actually be the reason you need to purge and reinstall).
In total, do this:
sudo service mysql stop #or mysqld sudo killall -9 mysql sudo killall -9 mysqld sudo apt-get remove --purge mysql-server mysql-client mysql-common sudo apt-get autoremove sudo apt-get autoclean sudo deluser -f mysql sudo rm -rf /var/lib/mysql sudo apt-get purge mysql-server-core-5.7 sudo apt-get purge mysql-client-core-5.7 sudo rm -rf /var/log/mysql sudo rm -rf /etc/mysql
All above commands in single line (just copy and paste):
sudo service mysql stop && sudo killall -9 mysql && sudo killall -9 mysqld && sudo apt-get remove --purge mysql-server mysql-client mysql-common && sudo apt-get autoremove && sudo apt-get autoclean && sudo deluser mysql && sudo rm -rf /var/lib/mysql && sudo apt-get purge mysql-server-core-5.7 && sudo apt-get purge mysql-client-core-5.7 && sudo rm -rf /var/log/mysql && sudo rm -rf /etc/mysql
Completely Uninstall MySQL Server in Ubuntu
While package management in Ubuntu, as in most Linux operating systems nowadays, makes it extremely easy to install, upgrade and delete a piece of software, some software is a bit more complex in nature and contains multiple configuration folders, etc.
One such complex software is MySQL Server. Uninstalling MySQL Server does not simply amount to running ‘apt purge‘ as is done usually. There are few small steps you can follow to completely uninstall MySQL Server from your Ubuntu machines.
Backup MySQL Databases in Linux
If you do not have any database created in MySQL, you can skip this step. If you have, before you remove MySQL Server from the system, make sure you take a backup of all your databases, so that when you reinstall it on another system or want to use the database on an existing server, you can simply restore them.
Remove MySQL Server in Ubuntu
The Ubuntu packages for MySQL Server start with ‘mysql-server’ and you can use apt purge command to remove all these packages.
$ sudo apt purge mysql-server*
As you can see, it has removed 3 packages that contain files for the server. The reason we use ‘purge‘ instead of ‘remove‘ is that the former removes the configuration files for the program as well, whereas the latter only removes the program binaries.
Remove MySQL Database Files and Logs
The command ‘apt purge‘ does remove the binaries and the configuration files, however, there are some more MySQL configuration files and the database files which are not touched by any package manager.
The configuration files are present in /etc/mysql and the security keys and other related files are stored in /var/lib/mysql.
$ ls /etc/mysql $ sudo ls /var/lib/mysql
Thus, these MySQL configuration files and database files need to be deleted manually.
$ sudo rm -r /etc/mysql /var/lib/mysql
If you have enabled logging for MySQL, make sure you delete the log files as well.
Remove Orphaned Packages Packages
Along with the MySQL Server packages installed by the package manager, there are some packages that are also installed as dependencies for the server. These are no longer required by the system, as the main package itself has been purged. They are also known as ‘Orphaned Packages’.
Run the following apt command to remove such packages.
Note that this will remove ALL orphaned packages, not only the ones orphaned by the purging of the MySQL Server. You can see in the output that MySQL Client packages are also being removed, as they are now useless without the server package.
Conclusion
We learned how to completely uninstall MySQL Server in Ubuntu in a few easy steps. Database deletions, upgrades, and installations should be handled with the utmost care, and data should be backed up from time to time, so as to prevent data-related disasters on a personal level or on an organizational level.
Thanks for reading and let us know your thoughts in the comments below!
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.
Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.
Was this article helpful? Please add a comment to show your appreciation and support.
RECOMMENDED ARTICLES
3 thoughts on “Completely Uninstall MySQL Server in Ubuntu”
Did not work because the system attempts to constantly re-install and then reports in a bad state. dpkg: warning: old mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
dpkg: trying script from the new package instead .
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action «stop» failed.
dpkg: error processing archive /var/cache/apt/archives/mysql-server-8.0_8.0.27-0ubuntu0.20.04.1_amd64.deb (—unpack):
new mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action «stop» failed.
Failed to start mysql.service: Unit mysql.service not found.
invoke-rc.d: initscript mysql, action «start» failed.
Unit mysql.service could not be found.
dpkg: error while cleaning up:
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
/var/cache/apt/archives/mysql-server-8.0_8.0.27-0ubuntu0.20.04.1_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1) will not install any other updates on the system whilst this loop remains. Reply
If the above command is not fixed, try to force the package installation using the following command.
$ sudo apt install -f OR $ sudo apt install --fix-broken
How To Remove MySQL Completely from Your Linux System
MySQL is a popular open-source relational database management system. However, sometimes you may need to remove MySQL from your Linux system due to various reasons such as upgrading to a newer version, replacing it with another database system, or simply uninstalling it. In this article, we’ll show you how to remove MySQL completely from your Linux system in a safe and effective manner.
Before we begin, it is recommended to back up your data and configuration files before uninstalling MySQL. You can use the mysqldump utility to back up your data or copy the entire MySQL data directory to a safe location.
Here’s the step-by-step guide to removing MySQL from your Linux system:
Step 1: Stop MySQL Service
First of all, you need to stop MySQL service on your system.
sudo systemctl stop mysql
This stops the MySQL service, allowing you to safely remove the database.
Step 2: Uninstall MySQL packages
First, uninstall all the MySQL packages installed on your server. Use one of the following commands as per your Linux distribution. The package names may vary based on the Operating system and installation types.
sudo apt remove mysql-server mysql-client
sudo apt autoremove
sudo apt autoclean
sudo dnf remove mysql-server mysql-client
This removes the MySQL packages and their dependencies from your system. The autoremove and autoclean commands remove unnecessary packages and clean up the package cache.
Step 3: Remove MySQL configuration and data files
Now we need to remove the MySQL data directory from the system which by default exists at /var/lib/mysql. If you didn’t find this, It may be changed to some other place, which you can find in my.cnf file with variable datadir. Delete the /var/lib/mysql directory from the system but we prefer to rename it to keep a backup of existing files.
sudo rm -rf /etc/mysql
sudo rm -rf /var/lib/mysql
This removes the MySQL configuration files and data directory. Be careful while removing these files, as they contain important data. Make sure to back up your data before removing these files.
Step 4: Verify the Removal
This following command lists all the packages installed on your system, and grep for the word ‘mysql’. If there are no MySQL packages installed, you have successfully removed MySQL from your system.
That’s it! You have now successfully removed MySQL from your Linux system. You can now install a different database system or simply enjoy a cleaner system without MySQL.
Conclusion
In conclusion, removing MySQL from your Linux system is a straightforward process, but it’s important to back up your data and follow the steps carefully to avoid any data loss. I hope this ultimate guide has been helpful in removing MySQL from your Linux system.