Ubuntu 20.10 Cannot Install or Uninstall MySQL
Solution 1:
This can sometimes be fixed by cleaning apt
a bit. In a terminal, try this:
sudo apt update
sudo apt clean
sudo apt autoremove
Now try to install the MySQL client. If the error persists, then you may need to "fix" the installation:
sudo apt --fix-broken install
sudo apt update && sudo apt upgrade
sudo dpkg --configure -a
sudo apt install -f
Now you should be able to install the client:
sudo apt install mysql-client
Note: Although you've removed MySQL Server, there are still some files lingering in /var/lib/mysql
. These are intentionally left behind after an uninstall. If you do not need any of the databases that were previously available, feel free to delete this directory. You may also have /etc/mysql
sticking around, which can also be deleted if you do not need the configuration files anymore.
Scrubbing MySQL From Ubuntu (18.04 and newer)
If MySQL refuses to play nicely, then you may need to follow these steps to completely scrub it from the system:
- Open Terminal (if it's not already open)
- Ensure the MySQL process is stopped (even if it's not running):
sudo systemctl stop mysqld
- Scrub the MySQL packages from your system:
And, just for the sake of completeness, let's make sure isn't an installation of MariaDB on the system:sudo apt purge mysql-server mysql-common mysql-server-core-* mysql-client-core-*
sudo apt purge mariadb-server
- Check for any remaining packages:
Ideally you will get zero results. However, if there is anything still installed, you may see something like this:sudo dpkg -l | grep mysql
If you do see values,ii libmysqlclient21:amd64 8.0.25-0ubuntu0.20.04.1 amd64 MySQL database client library ii php-mysql 2:7.4+75 all MySQL module for PHP [default] ii php7.4-mysql 7.4.3-4ubuntu2.4 amd64 MySQL module for PHP
apt purge
them off the system:
Do the same for MariaDB:sudo apt purge php-mysql php7.4-mysql libmysqlclient21
sudo dpkg -l | grep mariadb
- Scrub the file system of the MySQL directories (which are also used by MariaDB):
Double-check and scrub those files:sudo rm -rf /var/lib/mysql/ sudo rm -rf /etc/mysql/ sudo rm -rf /var/log/mysql
IMPORTANT: This command will remove any file starting withsudo find / -iname 'mysql*' -exec rm -rf {} \;
mysql
from your system without asking for confirmation. Be sure to use this with a great deal of care and consideration. - Remove the MySQL user account and group:
In the event you cannot delete the group, check to see if there are other user accounts that are part of the MySQL group:sudo deluser --remove-home mysql sudo delgroup mysql
If found, remove the users from the group, thenless /etc/passwd
delgroup
again. - Remove any third-party PPAs that may have been used to install specific builds of MySQL
- Update your source lists:
sudo apt autoremove -y sudo apt autoclean
- Grab a cup of coffee, because it's time to take a break ☕️
So long as you do not have some sort of XAMPP system configured on your machine, this should completely eliminate the database engine from your machine.