Monday, September 26, 2016

Rebuiding and Repairing Tables or Index on MySQL Database

MySQL Database edit/update error

Event: Users/Developers are complaining that they cannot edit/update the database.

Re-enacment & Recreation of edit/update/ delete on the database
Login to database using command line to monitor the log and event of the database activities. While simulating the event the following logs has been recorded in the database log.


160926  9:25:23 [ERROR] mysqld: Table './tmsdb/province' is marked as crashed and should be repaired
160926  9:25:23 [Warning] Checking table:   './tmsdb/province'
160926  9:25:24 [ERROR] mysqld: Table './tmsdb/municipality' is marked as crashed and should be repaired
160926  9:25:24 [Warning] Checking table:   './tmsdb/municipality'
160926  9:25:24 [ERROR] mysqld: Table './tmsdb/barangay' is marked as crashed and should be repaired
160926  9:25:24 [Warning] Checking table:   './tmsdb/barangay'
160926  9:26:35 [ERROR] mysqld: Table './tmsdb/farm' is marked as crashed and should be repaired
160926  9:26:35 [Warning] Checking table:   './tmsdb/farm'
160926  9:26:35 [ERROR] mysqld: Table './tmsdb/tms_account' is marked as crashed and should be repaired
160926  9:26:35 [Warning] Checking table:   './tmsdb/tms_account'


Resolution:
Try to backup the whole database before performing any repair or rebuild of the database.

Database backup & Restore:

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

Database & table repair:

REPAIR TABLE tablename;

No comments: