Score:1

Ubuntu 20.10 Cannot Install or Uninstall MySQL

cn flag

In trying to update my system prior to upgrading to 21.04 LTS, MySQL was giving errors that it could neither be updated nor repaired so I purged it with:

sudo apt purge mysql-server-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages will be REMOVED:
  mysql-server-8.0*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
(Reading database ... 555934 files and directories currently installed.)
Purging configuration files for mysql-server-8.0 (8.0.17-0ubuntu2) ...
Processing triggers for systemd (246.6-1ubuntu1.3) ...

However, now it will not reinstall.

sudo apt-get install mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-common : Conflicts: mysql-client-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
                Conflicts: mysql-client-core-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed

Something is apparently broken but not sure what so how do I proceed?

Here is some additional output based on the comments:

Sudo apt update
Hit:1 http://archive.ubuntu.com/ubuntu groovy InRelease
Hit:2 http://archive.ubuntu.com/ubuntu groovy-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu groovy-security InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
sudo apt clean

sudo apt autoremove
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo apt --fix-broken install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo apt update && sudo apt upgrade
Hit:1 http://archive.ubuntu.com/ubuntu groovy InRelease
Hit:2 http://archive.ubuntu.com/ubuntu groovy-updates InRelease
Hit:3 http://archive.ubuntu.com/ubuntu groovy-security InRelease
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo dpkg --configure -a

sudo apt install -f
Reading package lists... Done
Building dependency tree       
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Then tried to install mysql-client which gives errors on mysql-client in spite it not being installed:

sudo apt install mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-common : Conflicts: mysql-client-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
                Conflicts: mysql-client-core-8.0 but 

8.0.25-0ubuntu0.20.10.1 is to be installed

E: Unable to correct problems, you have held broken packages.

Additional attempts:

sudo apt install mysql-client
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 mysql-common : Conflicts: mysql-client-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
                Conflicts: mysql-client-core-8.0 but 8.0.25-0ubuntu0.20.10.1 is to be installed
E: Unable to correct problems, you have held broken packages.

sudo apt purge mysql-client-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-client-8.0' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

sudo apt purge mysql-client-core-8.0
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package 'mysql-client-core-8.0' is not installed, so not removed
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

It seems to be telling me that MySQL is not installed but that an installation of it is in conflict! How do I resolve this conundrum?

Score:3
in flag

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.

DonP avatar
cn flag
I added output from the above answer as mysql-client still won't install, apparently giving errors that it conflicts with itself in spite not being installed.
DonP avatar
cn flag
I am aware of the lingering files as I purposely did not remove the database folder or content.
DonP avatar
cn flag
Still stuck here. Ubuntu finally upgrading this morning itself to v21.04 but still MySQL seems to be stuck in an uninstallable mode.
in flag
Updated answer to include a scorched earth process to force MySQL off the system.
DonP avatar
cn flag
That did the trick, thank you!
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.