Remove mysql Completely error
Solution 1
What helped me
sudo systemctl disable mysql
then afterwards remove/purge or whatever.
sudo apt autoremove
did its job.... done
Solution 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
Anoop D
Updated on September 18, 2022Comments
-
Anoop D over 1 year
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 domysql -V
i am gettingmysql Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))
. Then i triedsudo apt-get purge mysql*
and it givesno 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 gettingRemoving 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 errorSetting 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 .
`
-
Anoop D almost 4 years@Kulfy its
/usr/share/mysql-common/configure-symlinks install mysql "$mysql_cfgdir/mysql.cnf"
-
Anoop D almost 4 years@Kulfy Should i reboot after this ?
-
Anoop D almost 4 yearsYea ........... what to do now ?
-
Anoop D almost 4 yearsSorry 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
-
Anoop D almost 4 yearsI 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
-
Anoop D almost 4 years
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
-
Anoop D almost 4 yearsCreated the file but still sub-process error . When i type
mysql
i am gettingRROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
-
Kulfy almost 4 yearsLet us continue this discussion in chat.
-
-
lepe over 3 years
systemctl disable mysql
and thenaptitude purge mysql-community-server
did the trick for me. -
Walty Yeung over 2 yearsI don't think
sudo apt-get dist-upgrade
is neccessary here.. -
Admin almost 2 yearsThis really helped.