Description:
Running mysql_upgrade on an instance where some tables need to be rebuilt
can result in errors about tables not existing.
For example the proxies_priv table on a clean 5.5->5.7 upgrade:
E:\mysql-5.7.7-rc-winx64\bin>mysql_upgrade --no-defaults --force --verbose -uroot
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv OK
mysql.db OK
mysql.engine_cost OK
mysql.event OK
mysql.func OK
mysql.general_log OK
mysql.gtid_executed OK
mysql.help_category OK
mysql.help_keyword OK
mysql.help_relation OK
mysql.help_topic OK
mysql.host OK
mysql.innodb_index_stats OK
mysql.innodb_table_stats OK
mysql.ndb_binlog_index OK
mysql.plugin OK
mysql.proc OK
mysql.procs_priv OK
mysql.proxies_priv
error : Table upgrade required. Please do "REPAIR TABLE `proxies_priv`" or dump/reload to fix it!
mysql.server_cost OK
mysql.servers OK
mysql.slave_master_info OK
mysql.slave_relay_log_info OK
mysql.slave_worker_info OK
mysql.slow_log OK
mysql.tables_priv OK
mysql.time_zone OK
mysql.time_zone_leap_second OK
mysql.time_zone_name OK
mysql.time_zone_transition OK
mysql.time_zone_transition_type OK
mysql.user OK
Repairing tables
mysql.proxies_priv
Note : TIME/TIMESTAMP/DATETIME columns of old format have been upgraded to the new format.
status : OK
Upgrading the sys schema.
Checking databases.
sys.sys_config OK
Repairing tables
test.proxies_priv <--------------------------
Error : Table 'test.proxies_priv' doesn't exist
status : Operation failed
Upgrade process completed successfully.
Checking if update is needed.
How to repeat:
create some databases and tables on ancient version.
upgrade to 5.7.7 and check that it tries to repair tables in wrong database.
Suggested fix:
Construct all SQL queries using fully qualified database and tables names.
Don't rely on the connection's "current db" property