Remove and reinstall mysql

6,305

Solution 1

I suggest you list what you have connected with mysql:

apt list --installed | grep mysql

It is just OK to purge mysql-common because w/o that package mysql will not work.

apt purge mysql-common

I tested on my end and it will also remove and purge this :

Purg mariadb-server [1:10.1.35+maria-1~bionic]
Purg mariadb-server-10.1 [1:10.1.35+maria-1~bionic]
Purg mariadb-client-10.1 [1:10.1.35+maria-1~bionic]
Purg percona-toolkit [3.0.6+dfsg-2]
Purg libdbd-mysql-perl [4.046-1]
Purg mariadb-server-core-10.1 [1:10.1.35+maria-1~bionic]
Purg mariadb-client-core-10.1 [1:10.1.35+maria-1~bionic]
Purg libmariadbclient18 [1:10.1.35+maria-1~bionic] [libmysqlclient18:amd64 ]
Purg libmysqlclient18 [1:10.1.35+maria-1~bionic]
Purg libmysqlclient20 [5.7.23-0ubuntu0.18.04.1]
Purg mariadb-common [1:10.1.35+maria-1~bionic]
Purg mysql-common [1:10.1.35+maria-1~bionic]

Solution 2

With user Sergiy Kolodyazhnyy's help I was able to detect that the problem was a process running in the background that was still blocking files. After killing that process and using sudo apt-get remove --purge mysql-\* to remove every last bit of mysql on the system I freshly installed mysql.

Share:
6,305

Related videos on Youtube

Axel
Author by

Axel

Augsburg based. Working on computational fluid dynamics of particle-laden flows.

Updated on September 18, 2022

Comments

  • Axel
    Axel almost 2 years

    I unfortunately messed up my mysql installation, when I thought I could just install mariadb next to it. Now I am not even able to remove and re-install it. As I have a lot of other things set up in this system I would like to avoid to freshly install Ubuntu.

    So far I tried everything that was proposed in this answer and also what is proposed here. However I end up with the following error message:

    Error message in terminal

    What can I do to rescue the system. I don't care about the data in the sql database as this is gone for good now I believe.

    When trying to sudo dpkg --purge --force-all mysql-server and sudo apt install mysql-server I get the error message:

    update-alternatives: error: alternative path /etc/mysql/mysql.cnf doesn't exist
    dpkg: error processing package mysql-server-5.7 (--configure):
    subprocess installed post-installation script returned error exit status 2
    dpkg: dpendency problems prevent configuration of mysql-server:
    mysql-server depends on mysql-server-5.7; however:
    Package mysql-server-5.7 is not configured yet. 
    
    dpkg: error processing package mysql-server (--configured): 
    dependency problems - leaving unconfigured
    No apport repport written because the error message indicates its a followup error from a previous failure. 
    Errors were encountered while processing: 
    mysql-server-5.8 
    mysql-server 
    E: Sub-process /usr/bin/dpkg returned an error code (1)
    
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy almost 6 years
      So I'm seeing it mentions missing /etc/mysql/my.cnf. That comes as part of mysql-common package. Consider doing apt-get remove --purge mysql-server first then try installing that mysql-common package , and finally reinstalling server and client package
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy almost 6 years
      Sorry for continuous editing on the comment. Kinda hard to type on mobile right now
    • Axel
      Axel almost 6 years
      Hi Sergiy, thanks for your comment. When I try doing sudo apt-get remove --purge it say Setting up mysql-server-5.7 and then tells me alternative path /etc/mysql/mysql.cnf does not exist. It also says my-sql-server-5.7 is not configured yet and ends with /usr/bin/dpkg returned an error code (1)
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy almost 6 years
      OK, same error. And does sudo dpkg-reconfigure mysql-server or mysql-server-5.7 return anything meaningful ?
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy almost 6 years
      If it keeps failing try askubuntu.com/a/369309/295286 Basically sudo dpkg --purge --force-all mysql-server
    • Axel
      Axel almost 6 years
      sudo dpkg-reconfigure mysql-server returns mysql-server is broken or not fully installed and sudo dpkg-reconfigure mysql-server-5.7 returns mysql-server-5.7 is broken or not fully installed :/
    • Axel
      Axel almost 6 years
      Ok and after sudo dpkg --purge --force-all mysql-server can I just trying to re-install by sudo apt-get install mysql-server?
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy almost 6 years
      Alright, I'll touch base later. Perhaps someone can come along with a better idea, but so far that's all I've got.
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy almost 6 years
      Yes, try reinstalling now.
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy almost 6 years