现象
mysql>select * from sys.host_summary;
ERROR 1356 (HY000): View 'sys.host_summary' references invalid table(s) or column(s) \
or function(s) or definer/invoker of view lack rights to use them
操作
想着把sys库删除了,然后用很早之前的备份恢复下sys库下。
mysql>set sql_log_bin=0;
mysql>drop database sys;
mysql>set sql_log_bin=1;
把备份文件复制到sys下后。
执行mysql_upgrade一直报错:
[root@db01 sys]# mysql_upgrade -uroot -p
……
The sys schema is already up to date (version 1.5.1).
Found 0 sys functions, but expected 22. Re-installing the sys schema.
Upgrading the sys schema.
mysql_upgrade: [ERROR] 1812: Tablespace is missing for table `sys`.`sys_config`.
找了很多方法都没有解决问题,仍然报这个错。
后来改用(MySQL5.7.24亲测有效):
在datadir下删除sys库,然后直接运行:
[root@db01 sys]# mysql_upgrade -uroot -p
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
……
Upgrade process completed successfully.
Checking if update is needed.
登录mysql后查询正常:
mysql> select * from sys.sys_config;
+--------------------------------------+-------+---------------------+--------+
| variable | value | set_time | set_by |
+--------------------------------------+-------+---------------------+--------+
| diagnostics.allow_i_s_tables | OFF | 2020-09-14 23:23:53 | NULL |
| diagnostics.include_raw | OFF | 2020-09-14 23:23:53 | NULL |
| ps_thread_trx_info.max_length | 65535 | 2020-09-14 23:23:53 | NULL |
| statement_performance_analyzer.limit | 100 | 2020-09-14 23:23:53 | NULL |
| statement_performance_analyzer.view | NULL | 2020-09-14 23:23:53 | NULL |
| statement_truncate_len | 64 | 2020-09-14 23:23:53 | NULL |
+--------------------------------------+-------+---------------------+--------+