Bug #92318 During debian packet upgrade, mysql_upgrade fails with error 3193
Submitted: 6 Sep 2018 10:59 Modified: 8 Oct 2018 8:37
Reporter: Nils Fahldieck Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Installing Severity:S3 (Non-critical)
Version:5.7.23 OS:Debian (9 / Stretch)
Assigned to: Lars Tangvald CPU Architecture:x86
Tags: configure, error 3193, mysql_upgrade

[6 Sep 2018 10:59] Nils Fahldieck
Description:
This bug happened when upgrading 'mysql-server-5.7' from version 5.7.22 to 5.7.23 from a debian package built by source.

MySQL is used in context of an usual LAMP environment. During apt's upgrade procedure, configuration of 'mysql-server-5.7' fails, when 'mysql_upgrade' wants to upgrade old tables. See this error message:

  mysql_upgrade: [ERROR] 3193: Cannot complete the operation because table is referenced by another connection.

Workaround: By stopping our webserver (and any (php) scripts of sorts) and restarting the upgrade, the upgrade procedure is successfully.

This is apt's output containing the problem:

  Setting up mysql-server-5.7 (995.7.23-1) ... 
  running systemctl stop mysql5.service...
  running systemctl start mysql5.service...
  running systemctl start mysql5.service...
  run mysql_upgrade...
  Checking if update is needed.
  Checking server version.
  Running queries to upgrade MySQL server.
  mysql_upgrade: [ERROR] 3193: Cannot complete the operation because table is referenced by another connection.
  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
  dpkg: dependency 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 (--configure):
   dependency problems - leaving unconfigured
  Errors were encountered while processing:
   mysql-server-5.7
   mysql-server

How to repeat:
Have a process, connecting to your database, as soon as it is available and upgrade mysql-server.

Suggested fix:
Configuration of mysql-server should ensure, that no connection to the database is allowed, as long as mysql_upgrade is still running. Maybe this behaviour can be implemented with a compile flag or some configuration.
[7 Sep 2018 7:31] Lars Tangvald
Thanks for the report.

What exactly do you mean by built from source? Is it the source for the packages available in Debian sid (so your packages are essentially equivalent to those) or something you constructed yourself?

Looking at the output it seems like it's the latter? You may want to take a look at https://salsa.debian.org/mariadb-team/mysql/blob/mysql-5.7/debian/master, which is the source for the MySQL packaging used in Debian sid. It does a temporary startup of the server for running mysql_upgrade, without networking and with a "hidden" socket file, to prevent clients from connecting while the upgrade is performed.
[9 Oct 2018 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".