
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to repair MySQL tables from the command line?
The repair of MySQL tables is only applicable to MyISAM engine type, not for InnoDB. Therefore, we need to change the Engine type to MyISAM.
The following is an example.
Creating a table
mysql> create table RepairTableDemo -> ( -> id int, -> name varchar(100) -> ); Query OK, 0 rows affected (0.51 sec)
To convert this table to engine type MyISAM, use ALTER.
mysql> ALTER TABLE RepairTableDemo ENGINE = MyISAM; Query OK, 0 rows affected (1.14 sec) Records: 0 Duplicates: 0 Warnings: 0
Inserting records into table.
mysql> insert into RepairTableDemo values(1,'John'),(2,'Carol'),(3,'Johnson'); Query OK, 3 rows affected (0.06 sec) Records: 3 Duplicates: 0 Warnings: 0
To display all records.
mysql> select *from RepairTableDemo;
The following is the output.
+------+---------+ | id | name | +------+---------+ | 1 | John | | 2 | Carol | | 3 | Johnson | +------+---------+ 3 rows in set (0.00 sec)
Let us now see the syntax to repair a table.
REPAIR TABLE yourTableName;
The following is the query −
mysql> REPAIR TABLE RepairTableDemo;
Here is the output. It shows that the repair status is fine.
+--------------------------+--------+----------+----------+ | Table | Op | Msg_type | Msg_text | +--------------------------+--------+----------+----------+ | business.repairtabledemo | repair | status | OK | +--------------------------+--------+----------+----------+ 1 row in set (0.10 sec)
- Related Articles
- How can we analyze the tables of a particular database from MySQL Server command line?
- How to upgrade MySQL server from command line?
- How can we get the list of tables in a particular database from MySQL Server command line?
- Connecting to MySQL database from the command line?
- Connect to MySQL database from command line
- How can we return to windows command shell from MySQL command line tool?
- How to find the MySQL data directory from command line in Windows?
- Hair Repair Line
- The MySQL Command-Line Client
- How to run TestNG from command line?
- How to open MySQL command line on Windows10?
- How to display all the MySQL tables in one line?
- How to run Python functions from command line?
- How to call Python module from command line?
- How to adjust display settings of MySQL command line?

Advertisements