优化并修复 MariaDB(MySQL)数据库损坏的表文件

您所在的位置:网站首页 lumion文件损坏修复 优化并修复 MariaDB(MySQL)数据库损坏的表文件

优化并修复 MariaDB(MySQL)数据库损坏的表文件

#优化并修复 MariaDB(MySQL)数据库损坏的表文件 | 来源: 网络整理| 查看: 265

平时维护网站的时候一定会遇到数据表崩溃,这可能是MySQL没有正常关闭或断电等原因导致。这时就需要我们手动修复表文件,通常可以通过数据库管理工具,例如:phpmyadmin 进行可视化修复。下面我讲解在Linux下通过命令修复损坏的表文件。

以下操作以本博客使用的 WordPress 程序演示,如果部分表存在问题则可以修复或优化。

登录MariaDB数据库

$ mysql -u root -p Enter password:[输入您的mysql或管理其数据库的密码] Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 84162 Server version: 10.3-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> use renwolecomdb;

查看当前所有数据表文件:

MariaDB [renwolecomdb]> show tables; +------------------------+ | Tables_in_renwolecomdb | +------------------------+ | wp_baidusubmit_sitemap | | wp_baidusubmit_urlstat | | wp_commentmeta | | wp_comments | | wp_links | | wp_options | | wp_postmeta | | wp_posts | | wp_term_relationships | | wp_term_taxonomy | | wp_termmeta | | wp_terms | | wp_usermeta | | wp_users | +------------------------+ 14 rows in set (0.00 sec)

如果感觉您的数据库某个表加载较慢,可以进行数据表优化,命令如下:

MariaDB [renwolecomdb]> OPTIMIZE TABLE wp_baidusubmit_urlstat; +------------------------------------+----------+----------+----------+ | Table | Op | Msg_type | Msg_text | +------------------------------------+----------+----------+----------+ |renwolecomdb.wp_baidusubmit_urlstat | optimize | status | OK | +------------------------------------+----------+----------+----------+ 1 row in set (0.11 sec)

上面已打印出详细的分析报告。

下面将修复被破坏的表文件,命令如下:

MariaDB [renwolecomdb]> REPAIR TABLE wp_baidusubmit_sitemap; +------------------------------------+--------+----------+----------+ | Table | Op | Msg_type | Msg_text | +------------------------------------+--------+----------+----------+ |renwolecomdb.wp_baidusubmit_sitemap | repair | status | OK | +------------------------------------+--------+----------+----------+ 1 row in set (0.00 sec)

修复成功。

修复 InnoDB 引擎的表文件,命令如下:

MariaDB [renwolecomdb]> REPAIR TABLE wp_commentmeta; +----------------------------+--------+----------+---------------------------------------------------------+ | Table | Op | Msg_type | Msg_text | +----------------------------+--------+----------+---------------------------------------------------------+ |renwolecomdb.wp_commentmeta | repair | note | The storage engine for the table doesn't support repair | +----------------------------+--------+----------+---------------------------------------------------------+ 1 row in set (0.00 sec)

提示错误报告:The storage engine for the table doesn't support repair.

上述报错说明该数据库InnoDB引擎数据表不支持修复。

但需要说明的是:

InnoDB损坏表的几率非常小,因为InnoDB是先写入日志,再写入数据库,因此InnoDB引擎比MyISAM健壮很多,而且他有自我修复能力,一般情况一旦InnoDB的数据文件损坏,只能找备份恢复。

所以我们平时做运维的一定要对数据备份、备份、再备份,以防万一。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3