Remove mysql Completely error

12,898

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
Share:
12,898
Anoop D
Author by

Anoop D

Updated on September 18, 2022

Comments

  • Anoop D
    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 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 .

    `

    • Anoop D
      Anoop D almost 4 years
      @Kulfy its /usr/share/mysql-common/configure-symlinks install mysql "$mysql_cfgdir/mysql.cnf"
    • Anoop D
      Anoop D almost 4 years
      @Kulfy Should i reboot after this ?
    • Anoop D
      Anoop D almost 4 years
      Yea ........... what to do now ?
    • Anoop D
      Anoop D almost 4 years
      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
    • Anoop D
      Anoop D almost 4 years
      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
    • Anoop D
      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
      Anoop D almost 4 years
      Created the file but still sub-process error . When i type mysql i am getting RROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
    • Kulfy
      Kulfy almost 4 years
  • lepe
    lepe over 3 years
    systemctl disable mysql and then aptitude purge mysql-community-server did the trick for me.
  • Walty Yeung
    Walty Yeung over 2 years
    I don't think sudo apt-get dist-upgrade is neccessary here..
  • Admin
    Admin almost 2 years
    This really helped.