[MDEV-22477] mysql_upgrade fails with sql_notes=OFF Created: 2020-05-05  Updated: 2023-04-27

Status: Open
Project: MariaDB Server
Component/s: Scripts & Clients
Affects Version/s: 5.5, 10.1, 10.2, 10.3, 10.4, 10.5
Fix Version/s: 10.4, 10.5

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Oleksandr Byelkin
Resolution: Unresolved Votes: 1
Labels: beginner-friendly

Attachments: File 10.3.mysql.dump    
Issue Links:
Relates
relates to MDEV-19650 Privilege bug on MariaDB 10.4 Closed

 Description   

mysql_upgrade, more exactly mysql_system_tables.sql, uses @@warning_count variable in the upgrade logic. The variable, in turn, depends on the value of sql_notes. It is ON by default, but when it is OFF, @@warnings_count is not incremented, and mysql_upgrade doesn't work as expected:

--source include/have_innodb.inc
 
set global sql_notes= 0;
--exec $MYSQL_UPGRADE

10.3 644d9f38

ERROR 1062 (23000) at line 617: Duplicate entry 'localhost-root--' for key 'PRIMARY'
FATAL ERROR: Upgrade failed

Apparently it happens always, on major and minor upgrades alike.

It wasn't very important before, as having it set to OFF before the upgrade is probably quite uncommon and means that the upgrade is run manually; and setting the value back to ON and re-running mysql_upgrade fixes the problem.

However, it becomes a bit more serious with the introduction of the new owner for mysql.user in the scope of MDEV-19650, as now, upon major upgrade (from pre-"mariadb.sys" version) after the initial failure setting the value back to ON and re-running mysql_upgrade does not fix the database, it remains inconsistent:

bb-10.4-MDEV-19650 15a750f2501b5ea8a5bc09c7047b8cef7e92d6ab

Phase 3/7: Fixing views
mysql.user
Error    : The user specified as a definer ('mariadb.sys'@'localhost') does not exist
error    : Corrupt
Phase 4/7: Running 'mysql_fix_privilege_tables'
ERROR 1449 (HY000) at line 7: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 16: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 59: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 68: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 86: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 172: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 181: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 183: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 194: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 199: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 202: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 326: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 329: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 397: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 402: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 404: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 407: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 411: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 416: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 432: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
ERROR 1449 (HY000) at line 440: The user specified as a definer ('mariadb.sys'@'localhost') does not exist
FATAL ERROR: Upgrade failed

For the convenience, below is is the test case for this failure. The dump file which it uses is attached. Dump is not important, the problem happens on a normal live upgrade from a version which doesn't have a pre-existing mariadb.sys user.

--source include/have_innodb.inc
 
--exec cp -r $MYSQLTEST_VARDIR/install.db $MYSQL_TMP_DIR/data
--let $restart_parameters= --datadir=$MYSQL_TMP_DIR/data
--source include/restart_mysqld.inc
 
--exec $MYSQL mysql < /tmp/10.3.mysql.dump
flush privileges;
 
set global sql_notes= 0;
--error 1
--exec $MYSQL_UPGRADE
 
set global sql_notes= 1;
--exec $MYSQL_UPGRADE
 
--let $restart_parameters=
--source include/restart_mysqld.inc


Generated at Thu Feb 08 09:15:01 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.