Upgrading to MySQL 5.7.15 crashes on Ubuntu 16.04

19,943

Solution 1

This solution solved my problem:

  1. Back-up your database files with permissions:

    sudo cp -avt /your/backup/directory /var/lib/mysql /etc/mysql/my.cnf
    
  2. Delete mysql files:

    sudo rm -rv /etc/mysql 
    
  3. Remove MySQL completely via running:

    sudo apt purge mysql-server mysql-server-5.7 mysql-server-core-5.7 mysql-client-5.7 mysql-client-core-5.7
    

    Use of Synaptic is recommended.

  4. Create these folders:

    sudo mkdir -p /etc/mysql/conf.d
    

    mysql setup didn't do it automatically and I don't know why.

  5. Install MySQL again

    sudo apt install mysql-server
    

    I used sudo apt install lamp-server^ instead to install other dependencies for PHP development.

  6. Stop MySQL:

    sudo service mysql stop 
    
  7. Restore databases and files:

    sudo cp -a /your/backup/directory/mysql /var/lib   
    sudo cp /your/backup/directory/my.cnf /etc/mysql 
    
  8. Restart MySQL:

    sudo service mysql start 
    

Solution 2

An easy solution is to sudo killall mysqld while the apt-get operation is running.

The apt operation just kept on running without any errors after that(!)

Solution 3

I managed to fix this without having to purge everything. It seems the problem is that the sys schema database was never created, so here's the solution:

  1. Clone https://github.com/mysql/mysql-sys and cd into the cloned folder.
  2. In a terminal, run mysql -u root -p < ./sys_57.sql (or sys_56.sql, depending on your version)

Enjoy mysql_upgrade working again. I guess this probably was, an upgrading scripts mess-up.

Solution 4

If your root@localhost account has no password then there is a bug in the postinstall process as stated here (see particularly the last comment of the thread)

  • purge all TMP* files in /var/lib/mysql-files
  • edit the file /var/lib/dpkg/info/mysql-server-5.7.postinst and comment (using #) the line 370 :

    echo "ALTER USER 'root'@'localhost' IDENTIFIED WITH 'auth_socket';" >> "$initfile"

  • run again sudo dpkg --configure -a

Solution 5

I had this issue too. Every time I started apt get and installed the process would hang after or during the DB update. None of the other solutions here worked.

In the end I purged

sudo apt purge mysql-server mysql-server-5.7

And followed the manual install from the instructions for mysql here

I then overwrote the data directory with my old data

sudo cp -Rfv /var/lib/mysql /usr/local/mysql/data

and finally added a systemd service like this

/lib/systemd/system/mysql.service

[Unit]
Description=MySQL Server
After=syslog.target
After=network.target

[Service]
Type=simple
PermissionsStartOnly=true
ExecStartPre=/bin/mkdir -p /var/run/mysqld
ExecStartPre=/bin/chown mysql:mysql -R /var/run/mysqld
ExecStart=/usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/lib/mysql/plugin --log-error=/var/log/mysql/error.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/run/mysqld/mysqld.sock --port=3306
TimeoutSec=300
PrivateTmp=true
User=mysql
Group=mysql
WorkingDirectory=/usr

[Install]
WantedBy=multi-user.target

Then ran

# systemctl daemon-reload
# systemctl enable mysql
# systemctl start mysql

Then everything seemed to be working as before and mysql was not breaking system updates

The downside, of course, is that I'll need to do manual updates in the future.

Share:
19,943

Related videos on Youtube

Omid
Author by

Omid

Contact me on facebook or visit my website and WebAdvice

Updated on September 18, 2022

Comments

  • Omid
    Omid over 1 year

    Last night I tried to upgrade my Ubuntu OS and MySQL 5.7.15 was one of the changes. It seems upgrading is successfull because mysql is propely working, but installation proccess has stop working with this message:

    This installation of MySQL is already upgraded to 5.7.15, 
    use --force if you still need to run mysql_upgrade
    

    I can't cancel the installation proccess in reqular way and just have to kill it. So it may cause some problem and also for every other installation (in the future) it tries to do it again.

    How to prevent this upgrade or solve it?

  • tread
    tread over 7 years
    dpkg: error while cleaning up: subprocess installed post-installation script returned error exit status 1 Errors were encountered while processing: mysql-server-5.7
  • tread
    tread over 7 years
    Key thing is removing: sudo rm /var/cache/debconf/config.dat, sudo rm /var/cache/debconf/passwords.dat and sudo rm /var/cache/debconf/templates.dat. Then purge everything. Then do a system reboot.
  • Omid
    Omid about 7 years
    Yes it is an issue with upgrading databases. Unfortunately I can't test your solution anymore to see if it's working or not.
  • Tsutomu
    Tsutomu about 7 years
    I had same problem and solved it with this procedure. I recommend a system reboot after purging MySQL. It seems that this prevents the issue reported by Stevie.
  • Xavier
    Xavier over 5 years
    I tried this solution on my mysql 5.7.22 installation that was reporting "This installation of MySQL is already upgraded to 5.7.22, use --force if you still need to run mysql_upgrade" and it worked like a charm
  • Gab
    Gab almost 5 years
    Oh dear me ! <3 You saved my life :p Note for posterity : you may want to prevent further mysql update (which will fail the same way) using apt-mark hold mysql-server-5.7
  • Eugene Mala
    Eugene Mala almost 4 years
    Error come backs with the next MySQL update :(
  • easwee
    easwee over 3 years
    This actually worked. Have my upvote
  • Nijat Mursali
    Nijat Mursali over 3 years
    Probably best answer.
  • Ugur
    Ugur over 3 years
    This saved my day! Running Ubuntu 18.x via Vagrant, and indeed: No password for root, so it was stuck.
  • Maxtrix
    Maxtrix over 3 years
    Worked perfectly! thanks for the insight!
  • JayJay
    JayJay over 3 years
    Works perfectly