3

after installing mariadb with mysql already installed, i had issues and mysql wasent working so i tried to uninstall mysql and the package broke. after frustrating hours of trying to fix this i stupidly deleted all the mysql files. at the moment:

ive tried dpkg -l | grep mysql, and get nothing

so i tried dpkg -l | grep mysql and got,

mysql-client-8.0                install
mysql-client-core-8.0           install
mysql-common                    install
mysql-server-8.0                install
mysql-server-core-8.0           install
php7.4-mysql                    install

after trying to remove mysql-server-8.0:

sudo dpkg --remove --force-remove-reinstreq mysql-server-8.0

i get:

(Reading database ... 219264 files and directories currently installed.)
Removing mysql-server-8.0 (8.0.22-0ubuntu0.20.10.2) ...
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
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

Is there a way to fix this and completely wipe mysql and then install mariadb?? If not i suppose the only way to fix this is to reinstall the os . thanks!!

joseph
  • 31
  • 1
  • 3
  • Use your package manage and remove all the MySQL and MariaDB packages. Then reinstall the database server you want. There are too many files with the same names between the two databases to not occasionally cause problems. – Dave Stokes Jan 29 '21 at 15:33
  • https://stackoverflow.com/questions/52867030/how-can-i-set-the-mysqls-password-in-the-mysqld-safe-is-running-scenario/52868910#52868910 – yusuf hayırsever Feb 19 '21 at 06:22

2 Answers2

12

After doing some looking, I found another post on ServerFault that details issues with the install script. I was having this same issue, and after ensuring that all MySQL files were removed I went to /var/lib/dpkg/info and ran sudo rm -rf ./mysql-*. After doing that you should be OK to run sudo dpkg --remove --force-remove-reinstreq mysql-server-8.0 followed by a sudo dpkg --purge mysql-server-8.0 .

This is a nuclear option and I would not recommend doing this until you are 100% sure that there are no more files from the MySQL install.

Omar Trkzi
  • 130
  • 1
  • 2
  • 13
Jcdiem
  • 121
  • 2
3
cd /var/lib/dpkg/info
sudo rm -rf ./mysql-*
sudo dpkg --remove --force-remove-reinstreq mysql-server-8.0

It is ok!

dragon fly
  • 31
  • 1