如何从命令行修复 MySQL 表?


MySQL 表的修复仅适用于 MyISAM 引擎类型,不适用于 InnoDB。因此,我们需要将引擎类型更改为 MyISAM。

以下是一个示例。

创建表

mysql> create table RepairTableDemo
   -> (
   -> id int,
   -> name varchar(100)
   -> );
Query OK, 0 rows affected (0.51 sec)

要将此表转换为引擎类型 MyISAM,请使用 ALTER。

mysql> ALTER TABLE RepairTableDemo ENGINE = MyISAM;
Query OK, 0 rows affected (1.14 sec)
Records: 0  Duplicates: 0  Warnings: 0

向表中插入记录。

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

要显示所有记录。

mysql> select *from RepairTableDemo;

以下是输出。

+------+---------+
| id   | name    |
+------+---------+
|    1 | John    |
|    2 | Carol   |
|    3 | Johnson |
+------+---------+
3 rows in set (0.00 sec)

现在让我们看看修复表的语法。

REPAIR TABLE yourTableName;

以下是查询 −

mysql> REPAIR TABLE RepairTableDemo;

这是输出。它表明修复状态良好。

+--------------------------+--------+----------+----------+
| Table                    | Op     | Msg_type | Msg_text |
+--------------------------+--------+----------+----------+
| business.repairtabledemo | repair | status   | OK       |
+--------------------------+--------+----------+----------+
1 row in set (0.10 sec)

更新于:30-7-2019

282 人浏览

开启你的事业

完成课程以获得认证

开始
广告
© . All rights reserved.