# Corruption and Repairs

<span class="TextRun SCXO226665310 BCX0" data-contrast="auto" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO226665310 BCX0">====================================================================================</span></span>

### <span class="TextRun SCXO226665310 BCX0" data-contrast="auto" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO226665310 BCX0">MySQL Check</span></span>

```
mysqlcheck -options database
```

##### <span class="TextRun SCXO226665310 BCX0" data-contrast="auto" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO226665310 BCX0">MySQL Check Options:  
</span></span>

<table border="1" id="bkmrk--c-checks-tables-for" style="border-collapse: collapse; width: 100%; height: 170.828px;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr style="height: 46.9062px;"><td style="height: 46.9062px;">-c</td><td style="height: 46.9062px;">Checks tables for errors. It performs a `CHECK TABLE` operation on each table in the specified databases.</td></tr><tr style="height: 47.2188px;"><td style="height: 47.2188px;">-r</td><td style="height: 47.2188px;">Attempts to repair corrupted tables. It performs a `REPAIR TABLE` operation on each corrupted table.</td></tr><tr style="height: 46.9062px;"><td style="height: 46.9062px;">-a</td><td style="height: 46.9062px;">Analyzes tables for optimal performance. It performs an `ANALYZE TABLE` operation on each table.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">-o</td><td style="height: 29.7969px;">Optimizes tables to reduce fragmentation and reclaim unused space. It performs an `OPTIMIZE TABLE` operation on each table.</td></tr><tr><td>--databases db1 db2 </td><td>Checks and repairs tables in multiple databases (`db1` and `db2`).</td></tr><tr><td>-A</td><td>Checks and repairs tables in all databases on the MySQL server.</td></tr></tbody></table>

<span class="TextRun SCXO226665310 BCX0" data-contrast="auto" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO226665310 BCX0">------------------------------------------------------------------------------------------------------------------------------------------------</span></span>

#### <span class="EOP SCXO226665310 BCX0"> When to use mysqlcheck -r  
</span>

- **Table Corruption**: Use `mysqlcheck -r` (or `mysqlcheck --repair`) when you suspect or know that one or more tables in your MySQL database are corrupted or have crashed.
- **Error Messages**: If MySQL reports errors such as "table is marked as crashed" or "table needs repair," `mysqlcheck -r` is a suitable approach to attempt repair.

#### Best Practices and Considerations

1. **Backup**: Always make a backup of your databases before attempting any repairs. While `mysqlcheck -r` is generally safe, there is a small risk of data loss if the repair process encounters unexpected issues.
2. **Table Locking**: During repair, `mysqlcheck` will lock tables to ensure data consistency. Depending on the size and activity of your database, this can cause downtime or impact performance.

<span class="TextRun SCXO226665310 BCX0" data-contrast="auto" lang="EN-GB" xml:lang="EN-GB"><span class="NormalTextRun SCXO226665310 BCX0">====================================================================================</span></span>