Question

Trying to purge mysql fails

Posted February 28, 2021 958 views
MySQLUbuntu 20.04

I really messed up my mysql installation trying to rapidly setup Owncloud on a new install of Ubuntu 20.04 LTS server. Sadly I already setup many services that are running well, so I just want to completely purge mysql and setup again from scratch. I have tried following various tutorials about

sudo apt-get purge mysql*

However, all variations end with this very similar error and I cannot continue and trying to ignore and re-install mysql just fails. How can I force remove all mysql of this box and start that again?

Thanks for any help.

Error:
(Reading database … 160886 files and directories currently installed.)
Removing mysql-server-8.0 (8.0.23-0ubuntu0.20.04.1) …
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action “stop” failed.
dpkg: error processing package mysql-server-8.0 (–remove):
installed mysql-server-8.0 package pre-removal script subprocess returned error exit status 1
dpkg: too many errors, stopping
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:
mysql-server-8.0
Processing was halted because there were too many errors.
E: Sub-process /usr/bin/dpkg returned an error code (1)

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
2 answers

Hi @jonathankonrad,

I’ve had the same issue before. What it worked for me in that case was :

sudo apt-get remove --purge mysql* 
sudo apt-get purge mysql*
sudo apt-get autoremove 
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysqlthen

Please give it a try one more time and see if it would work that way.

Looking forward to your reply!

Regards,
KFSys

  • Thank you for your help. These commands still end in error and I am unable to re-install. I believe I will need to format and re-install the system. Take care.

Hi there,

In addition to what KFSys already mentioned, I could suggest also taking a look at this answer here:

https://www.digitalocean.com/community/questions/completely-uninstall-mysql-server

Regards,
Bobby

  • Thank you. I tried each in order listed here by KFSys, then worked through the thread suggested by Bobby (Which is where I started) and it always ends with some variation of :

    dpkg: error processing package mysql-server-8.0 (–configure):
    installed mysql-server-8.0 package post-installation script subprocess returned error exit status 2
    Errors were encountered while processing:
    mysql-server-8.0
    E: Sub-process /usr/bin/dpkg returned an error code (1)

    Since nothing removes mysql, if I try to go in with “$ mysql” I get this:

    ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ’/var/run/mysqld/mysqld.sock’ (2)

    I think I will need to rebuild the server from scratch. I’ll look to the next weekend when I have a little more time. Thanks for trying.