8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

9.6.5 设置 MyISAM 表维护计划9.6.5 Setting Up a MyISAM Table Maintenance Schedule

定期对表进行检查是一个好主意,而不是等到出现问题才处理。检查和修复 MyISAM 表的一种方法是使用 CHECK TABLE 和 REPAIR TABLE 语句。请参阅 第 15.7.3 节,“表维护语句”。It is a good idea to perform table checks on a regular basis rather than waiting for problems to occur. One way to check and repair MyISAM tables is with the CHECK TABLE and REPAIR TABLE statements. See Section 15.7.3, “Table Maintenance Statements”.

检查表的另一种方法是使用 myisamchk。出于维护目的,你可以使用 myisamchk -s。-s 选项(--silent 的缩写)使 myisamchk 以静默模式运行,仅在发生错误时打印消息。Another way to check tables is to use myisamchk. For maintenance purposes, you can use myisamchk -s. The -s option (short for --silent) causes myisamchk to run in silent mode, printing messages only when errors occur.

启用自动 MyISAM 表检查也是一个好主意。例如,每当机器在更新过程中重启时,通常需要在进一步使用之前检查每个可能受影响的表。这些是“预期崩溃的表”。要使服务器自动检查 MyISAM 表,可以使用设置了 myisam_recover_options 系统变量的启动方式。参见 第 7.1.8 节,“服务器系统变量”。It is also a good idea to enable automatic MyISAM table checking. For example, whenever the machine has done a restart in the middle of an update, you usually need to check each table that could have been affected before it is used further. (These are “expected crashed tables.”) To cause the server to check MyISAM tables automatically, start it with the myisam_recover_options system variable set. See Section 7.1.8, “Server System Variables”.

您还应该在系统正常运行期间定期检查您的表。例如,您可以运行一个 cron 任务,每周检查一次重要表,在 crontab 文件中使用如下行:You should also check your tables regularly during normal system operation. For example, you can run a cron job to check important tables once a week, using a line like this in a crontab file:

35 0 * * 0 /path/to/myisamchk --fast --silent /path/to/datadir/*/*.MYI

这会打印出关于崩溃表的信息,以便您根据需要检查和修复它们。This prints out information about crashed tables so that you can examine and repair them as necessary.

首先,每晚对过去 24 小时内更新过的所有表执行 myisamchk -s。由于问题出现得不频繁,你可以将检查频率降低到每周一次左右。To start with, execute myisamchk -s each night on all tables that have been updated during the last 24 hours. As you see that problems occur infrequently, you can back off the checking frequency to once a week or so.

通常情况下,MySQL 表几乎不需要维护。如果您对具有动态大小行的 MyISAM 表(包含 VARCHAR、BLOB 或 TEXT 列)执行大量更新,或者有许多已删除行的表,您可能需要不时地对表进行碎片整理/回收空间。您可以通过对相关表使用 OPTIMIZE TABLE 来完成此操作。或者,如果您可以短暂停止 mysqld 服务器,可以进入数据目录并在服务器停止时使用此命令:Normally, MySQL tables need little maintenance. If you are performing many updates to MyISAM tables with dynamic-sized rows (tables with VARCHAR, BLOB, or TEXT columns) or have tables with many deleted rows you may want to defragment/reclaim space from the tables from time to time. You can do this by using OPTIMIZE TABLE on the tables in question. Alternatively, if you can stop the mysqld server for a while, change location into the data directory and use this command while the server is stopped:

$> myisamchk -r -s --sort-index --myisam_sort_buffer_size=16M */*.MYI