Upgrading to MySQL 5.7.15 crashes on Ubuntu 16.04

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?


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.