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:

  1. Open Terminal (if it's not already open)
  2. Ensure the MySQL process is stopped (even if it's not running):
    sudo systemctl stop mysqld
    
  3. Scrub the MySQL packages from your system:
    sudo apt purge mysql-server mysql-common mysql-server-core-* mysql-client-core-*
    
    And, just for the sake of completeness, let's make sure isn't an installation of MariaDB on the system:
    sudo apt purge mariadb-server 
    
  4. Check for any remaining packages:
    sudo dpkg -l | grep mysql
    
    Ideally you will get zero results. However, if there is anything still installed, you may see something like this:
    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
    
    If you do see values, apt purge them off the system:
    sudo apt purge php-mysql php7.4-mysql libmysqlclient21
    
    Do the same for MariaDB:
    sudo dpkg -l | grep mariadb
    
  5. Scrub the file system of the MySQL directories (which are also used by MariaDB):
    sudo rm -rf /var/lib/mysql/
    sudo rm -rf /etc/mysql/
    sudo rm -rf /var/log/mysql
    
    Double-check and scrub those files:
    sudo find / -iname 'mysql*' -exec rm -rf {} \;
    
    IMPORTANT: This command will remove any file starting with mysql from your system without asking for confirmation. Be sure to use this with a great deal of care and consideration.
  6. Remove the MySQL user account and group:
    sudo deluser --remove-home mysql
    sudo delgroup mysql
    
    In the event you cannot delete the group, check to see if there are other user accounts that are part of the MySQL group:
    less /etc/passwd
    
    If found, remove the users from the group, then delgroup again.
  7. Remove any third-party PPAs that may have been used to install specific builds of MySQL
  8. Update your source lists:
    sudo apt autoremove -y
    sudo apt autoclean
    
  9. 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.