mysql8:mysql 表已损坏,但 mysqlcheck 显示它们正常

mysql8:mysql 表已损坏,但 mysqlcheck 显示它们正常

我在 wsl2 下的 Ubuntu 20.04 中运行 mysql。

今天,当我启动 Windows 时,它以恢复模式启动“恢复:Windows 似乎未正确加载...”,就像它有时那样。重启后,mysql 不再启动。其他一切似乎都运行良好。

Mysql服务启动错误:

$ sudo service mysql start
 * Starting MySQL database server mysqld
su: warning: cannot change directory to /nonexistent: No such file or directory        [fail]

错误日志/var/log/mysql/error.log

2022-09-28T06:49:48.096514Z 0 [Warning] [MY-013143] [Server] Column count of mysql.user is wrong. Expected 51, found 37. The table is probably corrupted
2022-09-28T06:49:48.096523Z 0 [Warning] [MY-013143] [Server] Column count of mysql.db is wrong. Expected 22, found 20. The table is probably corrupted
2022-09-28T06:49:48.096528Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.tables_priv. The table is probably corrupted!
2022-09-28T06:49:48.096532Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.tables_priv. The table is probably corrupted!
2022-09-28T06:49:48.096535Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.tables_priv. The table is probably corrupted!
2022-09-28T06:49:48.096540Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.tables_priv. The table is probably corrupted!
2022-09-28T06:49:48.096544Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.columns_priv. The table is probably corrupted!
2022-09-28T06:49:48.096547Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.columns_priv. The table is probably corrupted!
2022-09-28T06:49:48.096551Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.procs_priv. The table is probably corrupted!
2022-09-28T06:49:48.096554Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.procs_priv. The table is probably corrupted!
2022-09-28T06:49:48.096558Z 0 [Warning] [MY-013139] [Server] Cannot load from mysql.procs_priv. The table is probably corrupted!
2022-09-28T06:49:48.096644Z 0 [ERROR] [MY-010316] [Server] Fatal error: Could not read the column 'authentication_string' from table 'mysql.user'. Please perform the MySQL upgrade procedure.
2022-09-28T06:49:48.096679Z 0 [ERROR] [MY-010952] [Server] The privilege system failed to initialize correctly. For complete instructions on how to upgrade MySQL to a new version please see the 'Upgrading MySQL' section from the MySQL manual.
2022-09-28T06:49:48.096713Z 0 [ERROR] [MY-010119] [Server] Aborting

如果我添加 /etc/mysql/mysql.conf.d/mysqld.cnf,我就可以启动 mysql

[mysqld]
skip_grant_tables

但当我运行 mysqlcheck 时,一切似乎都正常

$ sudo mysqlcheck --databases mysql
mysql.columns_priv                                 OK
mysql.component                                    OK
mysql.db                                           OK
mysql.default_roles                                OK
mysql.engine_cost                                  OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.global_grants                                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.password_history                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.replication_asynchronous_connection_failover OK
mysql.replication_asynchronous_connection_failover_managed OK
mysql.replication_group_configuration_version      OK
mysql.replication_group_member_actions             OK
mysql.role_edges                                   OK
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

另外,使用 --check-upgrade 标志,一切都是最新的。

$ sudo mysqlcheck --check-upgrade --databases mysql
mysql.columns_priv                                 Table is already up to date
...
mysql.user                                         Table is already up to date

有什么办法可以解决这个问题吗?还是我应该重新安装 mysql?

答案1

我从包含二进制数据的旧 mysql 转储导入数据库后,数据库已损坏。

不确定是否相关,但是当我使用 VsCode 打开 sql-dump 文件时,它上面有“␁”(标题开始)字符:

SQL 表情符号

在我导出所有数据库、重新安装 mysql 并导入数据(没有损坏的数据库)后,问题就解决了。

相关内容