--- /var/lib/dpkg/info/mysql-server-5.7.postinst.orig 2020-07-30 17:43:01.841030585 +0000 +++ /var/lib/dpkg/info/mysql-server-5.7.postinst 2020-07-30 18:25:16.731528765 +0000 @@ -131,6 +131,21 @@ mysql --no-defaults -u root --socket="$tmpdir/mysqld.sock" /dev/null 2>&1 } +# Check if in (super) read-only mode +# Usage: test_mysql_is_readonly +# Params: +# tmpdir - Location of mysqld.sock file +test_mysql_is_readonly() { + local tmpdir=$1 + local readonly=0 + readonly=$(mysql --no-defaults -u root --socket="$tmpdir/mysqld.sock" --skip-column-names --batch --execute "SELECT @@global.read_only OR @@global.super_read_only;" &2 else - # mysql_upgrade returns exit status 2 if the database is already upgraded - # (LP: #1566406) so ignore its exit status if it is 2. - result=0 - mysql_upgrade --no-defaults --socket="$tmpdir/mysqld.sock" || result=$? - if [ $result -ne 0 -a $result -ne 2 ]; then - echo "mysql_upgrade failed with exit status $result" >&2 - stop_server "$tmpdir" - rm -rf "$tmpdir" - exit 1 + # only run mysql_upgrade if NOT in read-only (LP: #1889472) + if ! test_mysql_is_readonly "$tmpdir"; then + # mysql_upgrade returns exit status 2 if the database is already upgraded + # (LP: #1566406) so ignore its exit status if it is 2. + result=0 + mysql_upgrade --no-defaults --socket="$tmpdir/mysqld.sock" || result=$? + if [ $result -ne 0 -a $result -ne 2 ]; then + echo "mysql_upgrade failed with exit status $result" >&2 + stop_server "$tmpdir" + rm -rf "$tmpdir" + exit 1 + fi + else + echo "mysql_upgrade skipped due to (super) read-only mode" fi # Stop the server stop_server "$tmpdir"