No cache version.

Caching disabled. Default setting for this page:enabled (code DEF204)
If the display is too slow, you can disable the user mode to view the cached version.

Rechercher dans le manuel MySQL

16.4.1 Repairing and Checking CSV Tables

The CSV storage engine supports the CHECK TABLE and REPAIR TABLE statements to verify and, if possible, repair a damaged CSV table.

When running the CHECK TABLE statement, the CSV file will be 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 will report an error. Checking a valid table produces output like that shown below:

  1. mysql> CHECK TABLE csvtest;
  2. +--------------+-------+----------+----------+
  3. | Table        | Op    | Msg_type | Msg_text |
  4. +--------------+-------+----------+----------+
  5. | test.csvtest | check | status   | OK       |
  6. +--------------+-------+----------+----------+

A check on a corrupted table returns a fault:

  1. mysql> CHECK TABLE csvtest;
  2. +--------------+-------+----------+----------+
  3. | Table        | Op    | Msg_type | Msg_text |
  4. +--------------+-------+----------+----------+
  5. | test.csvtest | check | error    | Corrupt  |
  6. +--------------+-------+----------+----------+

If the check fails, the table is marked as crashed (corrupt). Once a table has been marked as corrupt, it is automatically repaired when you next run CHECK TABLE or execute a SELECT statement. The corresponding corrupt status and new status will be displayed when running CHECK TABLE:

  1. mysql> CHECK TABLE csvtest;
  2. +--------------+-------+----------+----------------------------+
  3. | Table        | Op    | Msg_type | Msg_text                   |
  4. +--------------+-------+----------+----------------------------+
  5. | test.csvtest | check | warning  | Table is marked as crashed |
  6. | test.csvtest | check | status   | OK                         |
  7. +--------------+-------+----------+----------------------------+

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.

  1. mysql> REPAIR TABLE csvtest;
  2. +--------------+--------+----------+----------+
  3. | Table        | Op     | Msg_type | Msg_text |
  4. +--------------+--------+----------+----------+
  5. | test.csvtest | repair | status   | OK       |
  6. +--------------+--------+----------+----------+
Warning

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.


Find a PHP function

Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-se-csv-repair.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:en Manuel MySQL : https://dev.mysql.com/

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut