我最近成功将 MariaDB 从版本 5.6 升级到 10.3.39(从 RHEL 7 升级到 8)。但是,每次启动数据库时我都会收到以下消息:
systemd[1]: Starting MariaDB 10.3 database server...
mysql-prepare-db-dir[15294]: Database MariaDB is probably initialized in /sdb1/mysql already, nothing is done.
mysql-prepare-db-dir[15294]: If this is not the case, make sure the /sdb1/mysql is empty before running mysql-prepare-db-dir.
mysqld[15336]: 2024-04-18 9:49:42 0 [Warning] 'default-authentication-plugin' is MySQL 5.6 / 5.7 compatible option. To be implemented in later versions.
mysql-check-upgrade[15395]: The datadir located at /sdb1/mysql needs to be upgraded using 'mysql_upgrade' tool. This can be done using the following steps:
mysql-check-upgrade[15395]: 1. Back-up your data before with 'mysql_upgrade'
mysql-check-upgrade[15395]: 2. Start the database daemon using 'service mariadb start'
mysql-check-upgrade[15395]: 3. Run 'mysql_upgrade' with a database user that has sufficient privileges
mysql-check-upgrade[15395]: Read more about 'mysql_upgrade' usage at:
mysql-check-upgrade[15395]: https://mariadb.com/kb/en/mariadb/documentation/sql-commands/table-commands/mysql_upgrade/
systemd[1]: Started MariaDB 10.3 database server.
好吧,这些说明很清楚,所以我就照做了。但是,mysql_upgrade 调用失败了,如下所示:
Phase 1/7: Checking and upgrading mysql database
Processing databases
mysql
mysql.column_stats OK
mysql.columns_priv OK
mysql.db OK
[many more tables "OK"]
Phase 4/7: Running 'mysql_fix_privilege_tables'
ERROR 1813 (HY000) at line 77: Tablespace for table '`mysql`.`innodb_table_stats`' exists. Please DISCARD the tablespace before IMPORT
ERROR 1813 (HY000) at line 81: Tablespace for table '`mysql`.`innodb_index_stats`' exists. Please DISCARD the tablespace before IMPORT
ERROR 1146 (42S02) at line 642: Table 'mysql.innodb_index_stats' doesn't exist
ERROR 1243 (HY000) at line 643: Unknown prepared statement handler (stmt) given to EXECUTE
ERROR 1146 (42S02) at line 645: Table 'mysql.innodb_table_stats' doesn't exist
ERROR 1243 (HY000) at line 646: Unknown prepared statement handler (stmt) given to EXECUTE
ERROR 1146 (42S02) at line 650: Table 'mysql.innodb_index_stats' doesn't exist
ERROR 1146 (42S02) at line 654: Table 'mysql.innodb_table_stats' doesn't exist
ERROR 1146 (42S02) at line 657: Table 'mysql.innodb_table_stats' doesn't exist
FATAL ERROR: Upgrade failed
因此,似乎存在不存在的表的表空间。ALTER TABLE mysql.innodb_table_stats DISCARD TABLESPACE
当然会失败,因为表不存在。一些网页浏览显示,此类表空间位于孤立的 mysql/*.ibd 文件中。果然,它们就在那里。让我们删除它们:
# ls -l mysql/innodb_*
-rw-rw----. 1 mysql mysql 65536 Apr 18 10:10 mysql/innodb_index_stats.ibd
-rw-rw----. 1 mysql mysql 65536 Apr 18 10:10 mysql/innodb_table_stats.ibd
# rm -f mysql/innodb_*
# ls -l mysql/innodb_*
ls: cannot access 'mysql/innodb_*': No such file or directory
所以它们消失了。但是,mysql_upgrade 的下一次运行以同样的方式失败了,.ibd 文件又出现了。即使我停止服务器,删除有问题的 .ibd 文件,然后重新启动它,也会发生这种情况。
不知何故,mysql_update 首先创建有问题的表(否则,.ibd 文件从何而来?),然后删除它们但不删除表空间(不管它是什么),然后抱怨没有表的表空间,然后抱怨丢失的表。
这毫无意义。如何解决?