9

I am on Focal Fossa and i have mysql installed . I was trying to remove it and install mariadb . I tried sudo apt-get remove mysql but when i do mysql -V i am getting mysql Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu)). Then i tried sudo apt-get purge mysql* and it gives no matches found

I tried the following and getting the same error

sudo apt-get remove mysql-server

Setting up mysql-server-8.0 (8.0.20-0ubuntu0.20.04.1) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
/var/lib/dpkg/info/mysql-server-8.0.postinst: line 191: /usr/share/mysql-common /configure-symlinks: No such file or directory
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

when i try sudo dpkg -l | grep mysql

The result is

pi  mysql-client-8.0                           8.0.20-0ubuntu0.20.04.1                     amd64        MySQL database client binaries
ii  mysql-client-core-8.0                      8.0.20-0ubuntu0.20.04.1                     amd64        MySQL database core client binaries
ii  mysql-common                               5.8+1.0.5ubuntu2                            all          MySQL database common files, e.g. /etc/mysql/my.cnf
pF  mysql-server-8.0                           8.0.20-0ubuntu0.20.04.1                     amd64        MySQL database server binaries and system database setup
pi  mysql-server-core-8.0                      8.0.20-0ubuntu0.20.04.1                     amd64        MySQL database server binaries
ii  php7.3-mysql                               7.3.18-1+ubuntu20.04.1+deb.sury.org+1       amd64        MySQL module for PHP
ii  php7.4-mysql

I tried to sudo apt-remove mysql* each of these and was getting

Removing mysql-server-8.0 (8.0.20-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 preset unit: File mysql.service: Link has been severed
/usr/bin/deb-systemd-helper: error: systemctl preset failed on mysql.service: No such file or directory
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)

When i tried sudo apt-get -f install i got the error

Setting up mysql-server-8.0 (8.0.20-0ubuntu0.20.04.1) ...
Failed to stop mysql.service: Unit mysql.service not loaded.
invoke-rc.d: initscript mysql, action "stop" failed.
/var/lib/dpkg/info/mysql-server-8.0.postinst: line 191: /usr/share/mysql-common/configure-symlinks: No such file or directory
dpkg: error processing package mysql-server-8.0 (--configure):
installed mysql-server-8.0 package post-installation script subprocess returned error exit status 127
Errors were encountered while processing:
 mysql-server-8.0
E: Sub-process /usr/bin/dpkg returned an error code (1)

If somebody can help would be grateful .

`

8
  • @Kulfy its /usr/share/mysql-common/configure-symlinks install mysql "$mysql_cfgdir/mysql.cnf" Commented May 26, 2020 at 5:13
  • @Kulfy Should i reboot after this ? Commented May 26, 2020 at 5:32
  • Yea ........... what to do now ? Commented May 26, 2020 at 5:34
  • Sorry the same error again :( , actually not the same error Renaming removed key_buffer and myisam-recover options (if present) sed: can't read /etc/mysql/mysql.conf.d/mysqld.cnf: No such file or directory Commented May 26, 2020 at 5:38
  • I have tried it earlier , but was getting the same error ( sub-process ) , will try it again . 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 (--purge): installed mysql-server-8.0 package pre-removal script subprocess returned error exit status 1 Commented May 26, 2020 at 5:52

4 Answers 4

32

What helped me

sudo systemctl disable mysql

then afterwards remove/purge or whatever.

sudo apt autoremove 

did its job.... done

2
  • 4
    systemctl disable mysql and then aptitude purge mysql-community-server did the trick for me. Commented Jan 1, 2021 at 12:58
  • This really helped. Commented Jun 14, 2022 at 19:45
2

The actions you need to take: 1. Get all mysql-related components 2. Remove all mysql component installed 3. Clean up installation directory (you can rename the folder if you need the old data)

The yum way, which I found better:

yum list installed | grep mysql
yum remove mysql-client mysql-server mysql-common mysql-devel

The apt-get way:

sudo apt-get remove --purge mysql*
sudo apt-get purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get remove dbconfig-mysql
sudo apt-get dist-upgrade

Remove data & configuration

rm -rf /var/lib/mysql/
rm -rf /etc/my.cnf
1
  • I don't think sudo apt-get dist-upgrade is neccessary here.. Commented Jan 2, 2022 at 5:34
0

got the same problem and spend a whole day to solve it... try:

dpkg -r mysql-server
dpkg -r mysql-client-8.0(your version of mysql)
dpkg -r mysql-server-8.0(your version of mysql)
dpkg -r mysql-common
dpkg -r mysql

Ok...problem solved... the key is that when you uninstall or purged mysql, all the dependencies are lying there, and each of the dependencies rely on each other, so you have to find the first one relied by the others...

0

In my case a broken MySQL instance was still running. I killed it with:

sudo pkill mysql
sudo pkill mysqld

and then it worked.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.