如何在 MySQL 中避免“keycache 修復”命令?


要避免在 MySQL 中使用 keycache 修復,你需要按照以下語法執行 −

create table yourNewTableName as (select *from yourOldTableName);
alter table yourNewTableName add index(yourCoumnName);

首先,建立一個表 −

mysql> create table DemoTable
   (
   StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   StudentFirstName varchar(20),
   StudentLastName varchar(20)
   );
Query OK, 0 rows affected (0.24 sec)

使用 insert 命令在表中插入一些記錄 −

mysql> insert into DemoTable(StudentFirstName,StudentLastName) values('John','Doe');
Query OK, 1 row affected (0.05 sec)

mysql> insert into DemoTable(StudentFirstName,StudentLastName) values('David','Miller');
Query OK, 1 row affected (0.05 sec)

使用 select 語句顯示錶中的所有記錄 −

mysql> select *from DemoTable;

這將產生以下輸出 −

+-----------+------------------+-----------------+
| StudentId | StudentFirstName | StudentLastName |
+-----------+------------------+-----------------+
| 1         | John             | Doe             |
| 2         | David            | Miller          |
+-----------+------------------+-----------------+
2 rows in set (0.00 sec)

步驟 1 − 以下是避免在 MySQL 中使用“keycache 修復”的查詢。

mysql> create table DemoTable as (select *from DemoTable);
Query OK, 2 rows affected (0.34 sec)
Records: 2 Duplicates: 0 Warnings: 0

步驟 2 − 現在,使用 alter table

mysql> alter table DemoTable add index(StudentFirstName);
Query OK, 2 rows affected (0.57 sec)
Records: 2 Duplicates: 0 Warnings: 0

更新於: 30-Jul-2019

292 人瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.