前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mysql修复表的三个方法

mysql修复表的三个方法

作者头像
全栈程序员站长
发布2022-07-11 12:37:18
5.7K0
发布2022-07-11 12:37:18
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是全栈君。

断电或非正常关机可能导致MySQL数据库出现表损坏,特别是MyISAM表数据很大的时候。有三种方法,一种方法使用MySQL的repair table的sql语句,另一种方法是使用MySQL提供的myisamchk,,最后一种是mysqlcheck命令行工具。

1.repair table(建议方法,对MyISAM引擎表有用) (1)check table tabTest; 如果出现的结果说Status是OK,则不用修复,如果有Error,可以用:

(2)repair table tabTest; 进行修复,修复之后可以在用check table命令来进行检查。在新版本的phpMyAdmin里面也可以使用check/repair的功能。

2. myisamchk(该工具必须运行在服务终止条件下,对MyISAM引擎表有用)。 (1)myisamchk tablename.MYI 进行检测。

(2)myisamchk -of tablename.MYI 网上说的其它方法: 那么修复test表的方法为 myisamchk -r -q /var/lib/mysql/db/test.MYI 如果修复全部表,用这个命令 myisamchk -r -q /var/lib/mysql/db/*.MYI

3.运行mysqlcheck命令行工具(该工具可以在服务运行状态下执行)

转自:https://blog.csdn.net/orangleliu/article/details/63275154

检查特定的表: 如果应用中提示某个表坏了,使用下面的命令来检查。 $ mysqlcheck -c newmandela order -uroot -p Enter password: newmandela.order OK newmandela 是库名, order是表名,还需要输入用户名和密码

检查一个库中的所有表: $ mysqlcheck -c newmandela -uroot -p Enter password: newmandela.account OK newmandela.alarm OK newmandela.alarm_settings OK newmandela.auth_group OK newmandela.auth_group_permissions OK newmandela.auth_permission OK

检查所有库中的所有表: 全部的库和表都检查一遍了。 $mysqlcheck -c –all-databases -uroot -p Enter password: apmonitor.acinfo OK apmonitor.apdailysts OK apmonitor.apinfo OK apmonitor.apmonthsts OK apmonitor.apscanlog OK apmonitor.auth_group OK

如果只想检查某几个库呢? 可以使用 –databases 参数: $ mysqlcheck -c –databases newmandela radius -uroot -p Enter password: newmandela.account OK newmandela.alarm OK newmandela.alarm_settings OK newmandela.auth_group OK

使用 mysqlcheck 分析表: $ mysqlcheck -a radius payment_transactionrecord -uroot -p Enter password: radius.payment_transactionrecord Table is already up to date

上面的命令 用来分析 radius 库的 payment_transactionrecord表, -a 表示 analyze 使用 mysqlcheck 优化表: # mysqlcheck -o radius payment_transactionrecord -uroot -p Enter password: radius.payment_transactionrecord OK

-o 代表 optimize ,这里是优化 radius 库的 payment_transactionrecord 表 使用 mysqlcheck 修复表: # mysqlcheck -r radius payment_transactionrecord -uroot -p Enter password: radius.payment_transactionrecord OK

-r 代表 repair ,这里是 修复 radius 库的 payment_transactionrecord 表 检查,优化,修复表组合命令: # mysqlcheck -uroot -p –auto-repair -c -o newmandela Error: mysqlcheck doesn’t support multiple contradicting commands.

上面的命令报错了,去掉 -c # mysqlcheck -uroot -p –auto-repair -o newmandela Enter password: newmandela.account note : Table does not support optimize, doing recreate + analyze instead status : OK newmandela.alarm note : Table does not support optimize, doing recreate + analyze instead status : OK newmandela.alarm_settings note : Table does not support optimize, doing recreate + analyze instead status : OK

每张表都出现了 Table does not support optimize, doing recreate + analyze instead, 代表什么意思呢? 它的意思不是说 innodb 引擎不支持 优化,可以参考 http://stackoverflow.com/questions/30635603/what-does-table-does-not-support-optimize-doing-recreate-analyze-instead-me 的回答。 mysqlcheck 常用选项

A, –all-databases 表示所有库 -a, –analyze 分析表 -o, –optimize 优化表 -r, –repair 修复表错误 -c, –check 检查表是否出错 –auto-repair 自动修复损坏的表 -B, –databases 选择多个库 -1, –all-in-1 Use one query per database with tables listed in a comma separated way -C, –check-only-changed 检查表最后一次检查之后的变动 -g, –check-upgrade Check for version dependent changes in the tables -F, –fast Check tables that are not closed properly –fix-db-names Fix DB names –fix-table-names Fix table names -f, –force Continue even when there is an error -e, –extended Perform extended check on a table. This will take a long time to execute. -m, –medium-check Faster than extended check option, but does most checks -q, –quick Faster than medium check option

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/112096.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年2月1,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档