56

A software upgrade broke, among other things, mysql and I have not been able to get it back up yet.

Suspected cause: I had a near-full boot disk; the upgrade filled up the disk before completing and thus left everything in a mess. I have given the system more disk and moved /var to its own partition. I am still unsuccessfully trying to revive mysql.

Below is what I attempted so far (all as root). First, mysql does not start (443). Attempts to fix (444, 445) fail. Attempts to remove mysql and (?) apparmor fail (446, 7, 8). A more energetic attempt to remove mysql seems to succeed (449) and the previous errors are no longer seen (450, 1, 2). Mysql can't be reconfigured because it's no longer there (453) but attempting to reinstall it gives back the old error messages and we're back to square one (454).

I also checked this question (even though in my case it did not break because of an upgrade to 12.04: it was already working on 12.10) Fixing broken myslq-server package after upgrade to 12.04 and tried the suggestions in there (458, 461, 462) to no avail.

What else should I do?

This is on 3.5.0-25-generic #39-Ubuntu SMP Mon Feb 25 18:26:58 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

    443  service mysql start
         start: Job failed to start

    444  dpkg-reconfigure mysql-server-5.5
         /usr/sbin/dpkg-reconfigure: mysql-server-5.5
         is broken or not fully installed

    445  apt-get -f install
         ...
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         dpkg: dependency problems prevent configuration of
         mysql-server:
         mysql-server depends on mysql-server-5.5; however:
         Package mysql-server-5.5 is not configured yet.
         dpkg: error processing mysql-server (--configure):
         dependency problems - leaving unconfigured
         No apport report written because the error message
         indicates its a followup error from a previous failure.
         Errors were encountered while processing:
           mysql-server-5.5
           mysql-server
         E: Sub-process /usr/bin/dpkg returned an error code (1)

    446  apt-get remove mysql-server
         ...
         Removing mysql-server ...
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         No apport report written because MaxReports is reached already
         Errors were encountered while processing:
           mysql-server-5.5
         E: Sub-process /usr/bin/dpkg returned an error code (1)


    447  apt-get remove apparmor
         ...
         Package 'apparmor' is not installed, so not removed
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
         1 not fully installed or removed.
         After this operation, 0 B of additional disk space will be used. 
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         Errors were encountered while processing:
           mysql-server-5.5
         E: Sub-process /usr/bin/dpkg returned an error code (1)


    448  apt-get remove mysql-server
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         Package 'mysql-server' is not installed, so not removed
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
         1 not fully installed or removed.
         After this operation, 0 B of additional disk space will be used.
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         Errors were encountered while processing:
           mysql-server-5.5
         E: Sub-process /usr/bin/dpkg returned an error code (1)

    449  dpkg -r mysql-server-5.5
         (Reading database ... 322156 files and directories
         currently installed.)
         Removing mysql-server-5.5 ...
         Processing triggers for man-db ...
         Processing triggers for ureadahead ...

    450  apt-get remove mysql-server
         Reading package lists... Done
         Building dependency tree        
         Reading state information... Done
         Package 'mysql-server' is not installed, so not removed
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

    451  apt-get remove apparmor
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         Package 'apparmor' is not installed, so not removed
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

    452  apt-get -f install
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

    453  dpkg-reconfigure mysql-server-5.5
         /usr/sbin/dpkg-reconfigure: mysql-server-5.5 is broken
         or not fully installed

    454  apt-get install mysql-server
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         The following extra packages will be installed:
           mysql-server-5.5
         Suggested packages:
           tinyca mailx
         The following NEW packages will be installed:
           mysql-server mysql-server-5.5
         0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
         Need to get 0 B/8,851 kB of archives.
         After this operation, 32.8 MB of additional disk space
         will be used.
         Do you want to continue [Y/n]? 
         Preconfiguring packages ...
         Selecting previously unselected package mysql-server-5.5.
         (Reading database ... 322081 files and directories
         currently installed.)
         Unpacking mysql-server-5.5 (from 
         .../mysql-server-5.5_5.5.29-0ubuntu0.12.10.1_amd64.deb) ...
         Selecting previously unselected package mysql-server.
         Unpacking mysql-server (from 
         .../mysql-server_5.5.29-0ubuntu0.12.10.1_all.deb) ...
         Processing triggers for ureadahead ...
         Processing triggers for man-db ...
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         dpkg: dependency problems prevent configuration of mysql-server:
           mysql-server depends on mysql-server-5.5; however:
         Package mysql-server-5.5 is not configured yet.
         dpkg: error processing mysql-server (--configure):
         dependency problems - leaving unconfigured
         No apport report written because the error message
         indicates its a followup error from a previous failure.
         Errors were encountered while processing:
           mysql-server-5.5
           mysql-server
         E: Sub-process /usr/bin/dpkg returned an error code (1)


    458  apt-get remove --purge mysql-server
         Reading package lists... Done
         Building dependency tree       
         Reading state information... Done
         The following packages will be REMOVED:
           mysql-server*
         0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
         2 not fully installed or removed.
         After this operation, 116 kB disk space will be freed.
         Do you want to continue [Y/n]? 
         (Reading database ... 322159 files and directories
         currently installed.)
         Removing mysql-server ...
         Setting up mysql-server-5.5 (5.5.29-0ubuntu0.12.10.1) ...
         start: Job failed to start
         invoke-rc.d: initscript mysql, action "start" failed.
         dpkg: error processing mysql-server-5.5 (--configure):
         subprocess installed post-installation script
         returned error exit status 1
         Errors were encountered while processing:
           mysql-server-5.5
         E: Sub-process /usr/bin/dpkg returned an error code (1)

    461  touch /etc/apparmor.d/local/usr.sbin.mysqld
         (no output)

    462  service mysql start
         start: Job failed to start
st01
  • 1,083

7 Answers7

112

First, remove MySQL:

sudo apt purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo mv -iv /var/lib/mysql /var/tmp/mysql-backup
sudo rm -rf /var/lib/mysql*

Then reinstall:

sudo apt update
sudo apt install mysql-server
mysqld --initialize
sudo /usr/bin/mysql_secure_installation
Joren
  • 5,053
  • 8
  • 38
  • 54
  • 1
    perfect explanation ! – Postadelmaga Mar 11 '14 at 07:27
  • I think it's worth mentioning that --purge isn't necessarily what one wants, as it will remove configuration files as well. In the case of mysql specifically, I wonder if it would remove the dbs as well? – user50849 Nov 20 '14 at 09:28
  • 14
    To remove the configuration and database, you will have to remove /etc/mysql and /var/lib/mysql. – Anne van Rossum Apr 18 '15 at 14:24
  • after all remove steps:

    sudo apt-get install mysql-server ...

    mysql start/running, process 24591

    mysql stop/waiting

    mysql start/running, process 24772

    Checking if update is needed.

    Checking server version.

    Running queries to upgrade MySQL server.

    mysql_upgrade: [ERROR] 1049: Unknown database 'performance_schema'

    mysql_upgrade failed with exit status 5

    dpkg: error processing package mysql-server-5.7 (--configure):

    subprocess installed post-installation script returned error exit status 1

    – Crusader Aug 25 '16 at 10:32
  • 2
    You should stop mysql service to remove mysql-server – Viktor Sep 19 '16 at 07:41
  • If you just want to re-install mysql but don't want to remove your date, leave out the "sudo mysql_install_db" command. – Jim Maguire Mar 04 '17 at 06:58
  • 8
    2017-05-20 15:12:01 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize – flaudre May 20 '17 at 07:12
  • It seems to help if you reboot the machine between the uninstall and reinstall steps. I ran both back to back and had some strange results... Can't say for sure why this is. – jocull Oct 23 '17 at 17:51
  • 3
    in my case was also sudo rm -rf /etc/mysql – Vasilii Suricov Sep 09 '18 at 11:20
  • when do i move the data back? :D – Brunis Oct 07 '21 at 05:01
  • I was getting ... Failed! Error: SET PASSWORD has no significance for user 'root'@'localhost' when trying to set up the password, I fixed it following DigitalOcean how-to – Bilal Dec 26 '22 at 22:46
14

In Ubuntu 16.04 the way to fix it in my case was (please backup DBs first, databases will be lost):

sudo apt remove --purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo mv -iv /var/lib/mysql /var/tmp/mysql-backup
sudo rm -rf /var/lib/mysql*
sudo apt install mysql-server

(Somehow, my previous calls to apt purge mysql-server didn't seem to succeed. I thought that apt purge foo was equivalent to apt remove --purge foo...)

rubo77
  • 32,486
knocte
  • 996
12

I was getting the exact same errors and tried most of the steps you did, with the same results. The following finally worked for me.

apt-get purge mysql-server mysql-client mysql-common mysql-client-5.5 mysql-server-5.5

After that, mysql installed normally.

Tom Damon
  • 477
  • 3
  • 8
1

I am not sure what was the case for me, but the other solutions did not work, it kept giving an error. I tried this apt-get purge mysql-*, then autoremove and autoclean. After that installation was fine.

**

Be sure to backups your databases, the above command might delete them as well

**

dav
  • 131
0

For version MySQL 5.7 I removed MySQL as described before:

sudo apt purge mysql-server mysql-client mysql-common
sudo apt autoremove
sudo rm -rf /var/lib/mysql*

And installed it with help:

sudo apt-get update
sudo apt-get install mysql-server
mysql_secure_installation

To test if everything works:

systemctl status mysql.service

source

0

If you just run

sudo apt-get update
sudo apt-get install mysql-server

it will update mysql and this fixed the problem that i had after updating to 16.04 lts.

Or just run

sudo apt-get install lamp-server^

to update all of the server packages.

edwinksl
  • 23,789
-5

Install phpMyAdmin from the default Ubuntu repositories. Then run:

dpkg --configure mysql-server-5.5
apt-get purge mysql-server mysql-client mysql-common mysql-client-5.5 mysql-server-5.5
apt-get autoremove
apt-get autoclean
apt-get update
apt-get install  mysql-server
service mysql restart
Eric Carvalho
  • 54,385