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

7 Answers 7

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
11
  • 1
    perfect explanation ! Commented Mar 11, 2014 at 7:27
  • 14
    To remove the configuration and database, you will have to remove /etc/mysql and /var/lib/mysql. Commented Apr 18, 2015 at 14:24
  • 2
    You should stop mysql service to remove mysql-server
    – Viktor
    Commented Sep 19, 2016 at 7:41
  • 8
    2017-05-20 15:12:01 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
    – flaudre
    Commented May 20, 2017 at 7:12
  • 3
    in my case was also sudo rm -rf /etc/mysql Commented Sep 9, 2018 at 11:20
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...)

1
  • 1
    This is deleting all databases. A backup is required if any data is important.
    – flickerfly
    Commented Jul 25, 2016 at 18:14
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.

1
  • Oh my god. Thank you!! (Though I'm using my-sqlclient-5.7, not 5.5) Commented Dec 1, 2020 at 10:27
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

**

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.

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

-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
1
  • 5
    Why install phpMyAdmin? That is completely unnecessary.
    – Lucio
    Commented May 4, 2014 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .