Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

การ Rebuild หรือ Repair MySQL Tables และ Indexes

การเปลี่ยนแปลง tables และ indexes เกี่ยวกับการที่ MySQL จัดการ data types และ character sets การ repair/upgrade ที่จำเป็น รายงานโดย CHECK TABLE, mysqlcheck, หรือ mysql_upgrade

วิธี Rebuild Table

  • Dump and Reload Method
  • ALTER TABLE Method
  • REPAIR TABLE Method

Dump and Reload Method

ใช้เมื่อตารางต่าง version ไม่ handle ได้หลัง binary (in-place) upgrade/downgrade

Rebuild table โดย dump และ reload: mysqldump สร้าง dump file ให้ mysql reload

mysqldump db_name t1 > dump.sql
mysql db_name < dump.sql

Rebuild all tables ใน single database (ระบุ database name โดยไม่ใส่ table name):

mysqldump db_name > dump.sql
mysql db_name < dump.sql

Rebuild all tables ใน all databases (ใช้ --all-databases):

mysqldump --all-databases > dump.sql
mysql < dump.sql

ALTER TABLE Method

ใช้ "null" alteration ALTER TABLE statement เปลี่ยน table ให้ใช้ storage engine เดิม

ตัวอย่าง TblName เป็น InnoDB table:

ALTER TABLE TblName ENGINE = InnoDB;

REPAIR TABLE Method

ใช้ได้กับ MyISAM, ARCHIVE, CSV tables เท่านั้น ใช้ statement REPAIR TABLE หาก table check แสดงว่า file corrupt หรือต้อง upgrade

ตัวอย่าง repair MyISAM table:

REPAIR TABLE TblName;

mysqlcheck --repair ให้ command-line access to REPAIR TABLE สะดวกกว่า ใช้ --databases repair specific table หรือ --all-databases repair all tables:

mysqlcheck --repair --databases db_name ...
mysqlcheck --repair --all-databases