8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

18.4.1 修复和检查 CSV 表18.4.1 Repairing and Checking CSV Tables

CSV 存储引擎支持 CHECK TABLE 和 REPAIR TABLE 语句,用于验证并在可能的情况下修复损坏的 CSV 表。The CSV storage engine supports the CHECK TABLE and REPAIR TABLE statements to verify and, if possible, repair a damaged CSV table.

在运行CHECK TABLE语句时,CSV文件会通过检查正确的字段分隔符、转义字段(匹配或缺失的引号)、与表定义相比的正确字段数以及相应的CSV元文件的存在来验证其有效性。发现的第一个无效行会导致错误。检查有效表会产生如下所示的输出:When running the CHECK TABLE statement, the CSV file is checked for validity by looking for the correct field separators, escaped fields (matching or missing quotation marks), the correct number of fields compared to the table definition and the existence of a corresponding CSV metafile. The first invalid row discovered causes an error. Checking a valid table produces output like that shown here:

mysql> CHECK TABLE csvtest;
+--------------+-------+----------+----------+
| Table        | Op    | Msg_type | Msg_text |
+--------------+-------+----------+----------+
| test.csvtest | check | status   | OK       |
+--------------+-------+----------+----------+

对损坏表的检查会返回如下错误A check on a corrupted table returns a fault such as

mysql> CHECK TABLE csvtest;
+--------------+-------+----------+----------+
| Table        | Op    | Msg_type | Msg_text |
+--------------+-------+----------+----------+
| test.csvtest | check | error    | Corrupt  |
+--------------+-------+----------+----------+

要修复表,请使用 REPAIR TABLE,它会尽可能从现有的 CSV 数据中复制有效行,然后用恢复的行替换现有的 CSV 文件。超过损坏数据的行将丢失。To repair a table, use REPAIR TABLE, which copies as many valid rows from the existing CSV data as possible, and then replaces the existing CSV file with the recovered rows. Any rows beyond the corrupted data are lost.

mysql> REPAIR TABLE csvtest;
+--------------+--------+----------+----------+
| Table        | Op     | Msg_type | Msg_text |
+--------------+--------+----------+----------+
| test.csvtest | repair | status   | OK       |
+--------------+--------+----------+----------+
Warning

在修复过程中,只有从 CSV 文件中到第一个损坏行的行会被复制到新表。第一个损坏行之后到表尾的所有其他行都会被删除,即使是有效行也不例外。During repair, only the rows from the CSV file up to the first damaged row are copied to the new table. All other rows from the first damaged row to the end of the table are removed, even valid rows.