# REPAIR TABLE

## Syntax

{% tabs %}
{% tab title="Current" %}

```sql
REPAIR [NO_WRITE_TO_BINLOG | LOCAL] TABLE
    tbl_name [, tbl_name] ...
    [QUICK] [EXTENDED] [USE_FRM] [FORCE
```

{% endtab %}

{% tab title="< 11.5" %}

```
REPAIR [NO_WRITE_TO_BINLOG | LOCAL] TABLE
    tbl_name [, tbl_name] ...
    [QUICK] [EXTENDED] [USE_FRM]
```

{% endtab %}
{% endtabs %}

## Description

`REPAIR TABLE` repairs a possibly corrupted table. By default, it has the same effect as

```sql
myisamchk --recover tbl_name
```

or

```sql
aria_chk --recover tbl_name
```

See [aria\_chk](/docs/server/clients-and-utilities/aria-clients-and-utilities/aria_chk.md) and [myisamchk](/docs/server/clients-and-utilities/myisam-clients-and-utilities/myisamchk.md) for more.

`REPAIR TABLE` works for [Archive](/docs/server/server-usage/storage-engines/archive.md), [Aria](/docs/server/server-usage/storage-engines/aria.md), [CSV](/docs/server/server-usage/storage-engines/csv.md), and [MyISAM](/docs/server/server-usage/storage-engines/myisam-storage-engine.md) tables. For [InnoDB](/docs/server/server-usage/storage-engines/innodb.md), see [recovery modes](/docs/server/server-usage/storage-engines/innodb/innodb-troubleshooting/innodb-recovery-modes.md). For CSV, see also [Checking and Repairing CSV Tables](/docs/server/server-usage/storage-engines/csv/checking-and-repairing-csv-tables.md). For Archive, this statement also improves compression. If the storage engine does not support this statement, a warning is issued.

This statement requires [SELECT and INSERT privileges](/docs/server/reference/sql-statements/account-management-sql-statements/grant.md) for the table.

By default, `REPAIR TABLE` statements are written to the [binary log](/docs/server/server-management/server-monitoring-logs/binary-log.md) and will be [replicated](/docs/server/server-usage/storage-engines/myrocks/myrocks-and-replication.md). The `NO_WRITE_TO_BINLOG` keyword (`LOCAL` is an alias) will ensure the statement is not written to the binary log.

{% tabs %}
{% tab title="Current" %}
`REPAIR TABLE` statements are not logged to the binary log if [read\_only](/docs/server/server-management/variables-and-modes/server-system-variables.md#read_only) is set. See also [Read-Only Replicas](/docs/server/ha-and-performance/standard-replication/read-only-replicas.md).
{% endtab %}

{% tab title="< 10.3.19" %}
`REPAIR TABLE` statements are logged to the binary log.
{% endtab %}
{% endtabs %}

When an index is recreated, the storage engine may use a configurable buffer in the process. Incrementing the buffer speeds up the index creation. [Aria](/docs/server/server-usage/storage-engines/aria.md) and [MyISAM](/docs/server/server-usage/storage-engines/myisam-storage-engine.md) allocate a buffer whose size is defined by [aria\_sort\_buffer\_size](/docs/server/server-usage/storage-engines/aria/aria-system-variables.md) or [myisam\_sort\_buffer\_size](/docs/server/server-usage/storage-engines/myisam-storage-engine/myisam-system-variables.md), also used for [ALTER TABLE](/docs/server/reference/sql-statements/data-definition/alter/alter-table.md).

### QUICK

When specified, `REPAIR TABLE` will not modify the data file, only attempting to repair the index file. The same behavior can be achieved with [myisamchk --recover --quick](/docs/server/clients-and-utilities/myisam-clients-and-utilities/myisamchk.md#repairing-tables).

### EXTENDED

Creates the index row by row rather than sorting and creating a single index. Similar to [myisamchk --safe-recover](/docs/server/clients-and-utilities/myisam-clients-and-utilities/myisamchk.md#repairing-tables).

### USE\_FRM

For use only when the index file is missing or its header corrupted. MariaDB then attempts to recreate it using the `.frm` file. There is no equivalent [myisamchk](/docs/server/clients-and-utilities/myisam-clients-and-utilities/myisamchk.md) option.

### FORCE

{% tabs %}
{% tab title="Current" %}
The `FORCE` argument allows to first run internal repair to fix damaged blocks and then follow it up with `ALTER TABLE` ([MDEV-33449](https://jira.mariadb.org/browse/MDEV-33449)).
{% endtab %}

{% tab title="< 11.5" %}
The `FORCE` option is not available.
{% endtab %}
{% endtabs %}

### Partitioned Tables

`REPAIR TABLE` is also supported for [partitioned tables](/docs/server/server-usage/partitioning-tables.md) with the [ALTER TABLE ... REPAIR PARTITION](/docs/server/reference/sql-statements/data-definition/alter/alter-table.md) statement. However, the `USE_FRM` option cannot be used with this statement on a partitioned table. See [Repairing Partitions](/docs/server/server-usage/partitioning-tables/partitioning-overview.md#repairing-partitions) for details.

### Progress Reporting

The [Aria](/docs/server/server-usage/storage-engines/aria.md) storage engine supports [progress reporting](broken://spaces/WCInJQ9cmGjq1lsTG91E/pages/KgSCnuNXCMSK6rHfTpO5) for this statement.

## See Also

* [mariadb-check](/docs/server/clients-and-utilities/table-tools/mariadb-check.md)
* [aria\_chk](/docs/server/clients-and-utilities/aria-clients-and-utilities/aria_chk.md)
* [myisamchk](/docs/server/clients-and-utilities/myisam-clients-and-utilities/myisamchk.md)

<sub>*This page is licensed: GPLv2, originally from*</sub> [<sub>*fill\_help\_tables.sql*</sub>](https://github.com/MariaDB/server/blob/main/scripts/fill_help_tables.sql)

{% @marketo/form formId="4316" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mariadb.com/docs/server/reference/sql-statements/table-statements/repair-table.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
