1. 異常描述
使用xtrabackup對主庫進行備份,在從節點主機上進行恢復,并將還原后的實例部署為主庫的從節點。在啟動介質與主庫版本一致的情況下,啟動主從同步后,日志出現如下錯誤:
2022-10-30T11:44:17.442001Z 296 [ERROR] InnoDB: Column table_name in table `mysql`.`innodb_table_stats` is VARCHAR(597) NOT NULL but should be VARCHAR(192) NOT NULL (length mismatch).
2022-10-30T11:44:17.442029Z 296 [ERROR] InnoDB: Fetch of persistent statistics requested for table `testdb1`.`tb1` but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2022-10-30T11:44:17.567223Z 296 [ERROR] InnoDB: Column table_name in table `mysql`.`innodb_table_stats` is VARCHAR(597) NOT NULL but should be VARCHAR(192) NOT NULL (length mismatch).
2022-10-30T11:44:17.567240Z 296 [ERROR] InnoDB: Fetch of persistent statistics requested for table `testdb2`.`tb1` but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
以上錯誤一般都是數據庫版本不一致導致。但是查看啟動命令是正常的
/usr/local/mysql5.7/bin/mysqld_safe --defaults-file=/app/data/mysql3307/etc/my.cnf
對應的版本也是符合預期的:
[ops@ck2 ~]$ /usr/local/mysql5.7/bin/mysqld --version
/usr/local/mysql5.7/bin/mysqld Ver 5.7.25-28 for Linux on x86_64 (Percona Server (GPL), Release 28, Revision c335905)
但是登錄數據庫中查看版本:

確實與啟動的版本不一致。
2. 解決方案
查看本機上mysql是否有多個版本的啟動文件

經查,確實如此。而第一個版本正式啟動后數據庫里檢測到的版本。

2.1 解決思路
檢查配置文件:
因數據庫啟動時與配置文件中的basedir也有關系,先檢查配置文件:發現沒問題

檢查環境變量
export MYSQL_HOME=/app/mysql5.7
export MY_BASEDIR_VERSION=/app/mysql5.7
export PATH=/app/mysql5.7/bin:/app/mysql5.7/scripts:$PATH
export LD_LIBRARY_PATH=/app/mysql5.7/lib
發現環境變量里配置的確實是mysql5.7.18的路徑。
2.2 調整環境變量
將對應的路徑改為當前版本的路徑
export MYSQL_HOME=/usr/local/mysql5.7
export MY_BASEDIR_VERSION=/usr/local/mysql5.7
export PATH=/usr/local/mysql5.7/bin:/usr/local/mysql5.7/scripts:$PATH
export LD_LIBRARY_PATH=/usr/local/mysql5.7/lib
2.3 重啟數據庫
關閉數據庫
mysql> set global innodb_fast_shutdown=0;
Query OK, 0 rows affected (0.00 sec)
mysql> shutdown;
啟動數據庫
numactl --interleave=all /usr/local/mysql5.7/bin/mysqld_safe --defaults-file=/app/data/mysql3307/etc/my.cnf &
查看版本,是預期的情況了。

檢查配置文件: 也沒有再出現對應的錯誤了,至此問題解決。