웹프로그래밍

Global It Leader!!


MySql


 
 

테이블의 오류 검사및 복구

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 4,588회 작성일 12-02-29 05:53

본문

테이블의 오류 검사및 복구

오류의 원인: 사용자의 실수나 하드웨어적인 문제로 인해서 MySQL에 오류가 생길 수 있다.
예를 들면 MySQL이 데이블에 쓰기를 하는 동안에 전원이 중단되는 경우와 MySQL 테이블에 쓰기를 하는 도중에 불완전하게 MySQL이  종료하는 경우이다. 또한 실수로 테이블의 구조를 저장하고 있는 .frm 파일이 삭제되는 경우이다. 이러한 경우를 대비하여 MySQL에는 isamchk/myisamchk라는 테이블을 검사하고 오류를 수정하는 유틸리티가 포함되어 있다. isamchk/myisamchk는 테이블을 고치는 일 외에도 테이블에서 레코드들이 자주 삭제되었을 경우 인덱스를 재정렬하여

속도를 빠르게 하는 일에도 쓰일 수 있다.


데이블을 복구할 경우 MySQL을 종료한 후 복구하는 것이 바람직하다.

고치고자 하는 테이블이 있는 데이터베이스의  디렉토리로 이동한 후
myisamchk 명령을 이용하여 데이블의 오류를 검사한다.

MySQL이 실행 중일 경우 LOCK TABLE을 이용하여 테이블을 잠가야 한다.

mysql>LOCK TABLE table_name READ;


#myisamchk table_name

위 명령은 기본적인 검사만 수행한다. 에러메시지가 나타나지 않으면 테이블에 오류가 없다는 것이다.

[root@DWSM DBERING]# myisamchk CALLUSE
Checking MyISAM file: CALLUSE
Data records:  233641   Deleted blocks:       0
myisamchk: warning: Table is marked as crashed
myisamchk: warning: 1 client is using or hasn't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
myisamchk: error: Found key at page 17045504 that points to record outside datafile
- check record links
myisamchk: error: Checksum for key:  1 doesn't match checksum for records
myisamchk: error: Checksum for key:  2 doesn't match checksum for records
myisamchk: error: Checksum for key:  3 doesn't match checksum for records
MyISAM-table 'CALLUSE' is corrupted
Fix it using switch "-r" or "-o"

정확한 검사를 수행하기 위해서는 --extend-check 옵션을 주면 된다. 시간은 조금 더 걸린다.


#myisamchk --extend-check table_name

[root@DWSM DBERING]# myisamchk --extend-check CALLUSE
Checking MyISAM file: CALLUSE
Data records:  233641   Deleted blocks:       0
myisamchk: warning: Table is marked as crashed
myisamchk: warning: 1 client is using or hasn't closed the table properly
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
myisamchk: error: Found key at page 17045504 that points to record outside datafile
- check records and index references
myisamchk: error: Record at:   11035056  Can't find key for index:  2
MyISAM-table 'CALLUSE' is corrupted
Fix it using switch "-r" or "-o"
[root@DWSM DBERING]#

mysql>FLUSH TABLES;

READ LOCK은 테이블을 읽기만 가능하고 쓰기는 잠그는 기능을 한다. 테이블의 오류를 검사할 때는 테이블을 읽기만 하므로 READ LOCK을 하면 된다. 반대로 테이블을 복구할 때는 테이블에 쓰기를 하므로 WRITE LOCK을 해야 한다. FLUSH TABLES는 MySQL이 테이블의 내용을 변경하였을 경우 변경된 내용이 메모리에만 있고 실제 물리적인 테이블 파일에 기록하지 않았을 경우 파일에 기록하라는 것을 나타내는 SQL 문이다. MySQL은 LOCK TABLE 도중에 클라이언트 프로그램이 종로할 경우 자동으로 LOCK을 해제하기 때문에 isamchk/myisamchk를 통해 테이블 검사가 종료되면 UNLOCK TABLE을 실행해야 한다.

mysql>UNLOCK TABLE;

 

myisamchk를 이용한 데이블 복구

#myisamchk --recover --quick table_name

--quick 옵션은 인덱스 파일만 복구하므로 빠르게 복구할 수 있다. 그러나 오류가 해결되지 않으면 다음과 같은 명령을 이용할 수 있다.

[root@DWSM DBERING]# myisamchk --recover --quick CALLUSE
- check record delete-chain
- recovering (with sort) MyISAM-table 'CALLUSE'
Data records: 233641
- Fixing index 1
- Fixing index 2
- Fixing index 3
[root@DWSM DBERING]#
#myisamchk --recover table_name

위의 명령은 인덱스 파일 외에 데이터 파일도 검사하여 복구하게 된다. 이 명령으로도 오류가 남아 있다면 다음과  같은 명령을 사용한다.
이 명령은 속도는 느리지만 --recover 옵션으로 고칠 수 없는 오류도 고칠 수 있다.

#myisamchk --safe-recover table_name  <- 본인은 이것을 이용해서 복귀함.
#myisamchk --safe-recover -f table_name

myisamchk를 이용하여 테이블을 복구할 때에 MySQL이 실행중이라면 WRITE LOCK을 걸어야 한다.
창을 두 개 띄어 놓고 한 창에서는 LOCK TABLE을 이용하고, 다른 창에서는 ismachk/myisamchk를 이용하면 된다.
주의할 점은 테이블을 복구할 때는 WRITE LOCK을 걸어야 한다.

mysql>LOCK TABLE WRITE;
mysql>FLUSH TABLES;

복구완료된 상태

[root@DWSM DBERING]# myisamchk --extend-check CALLUSE;
Checking MyISAM file: CALLUSE
Data records:  233641   Deleted blocks:       0
- check file-size
- check record delete-chain
- check key delete-chain
- check index reference
- check data record references index: 1
- check data record references index: 2
- check data record references index: 3
- check records and index references
[root@DWSM DBERING]#

[AP에서 발생한 로그]

15:40:37.070757 > TRACE :[On_CMD_VMS_STATISTIC] phone:2881,calling_number:0318795096,   start_time:2007-08-24 15:37:59,end_time:2007-08-24 15:40:37,tel_time:00:02:38,in_out:1,type:1
15:40:37.070777 > TRACE :[db_insert] query(insert into CALLUSE(phone, calling_number, start_time, end_time, tel_time, in_out, call_type) values('2881','0318795096','2007-08-24 15:37:59','2007-08-24 15:40:37','00:02:38',1, 1)) size(181)
15:40:37.070849 > TRACE :[db_insert] mysql Alive!!
15:40:37.071189 > TRACE :[db_insert] Success!
15:40:37.071212 > TRACE :[On_CMD_VMS_STATISTIC] Success!!!
15:40:39.190607 > TRACE :[ep_client.c.230] recvEpoint() iLen(116)
15:40:39.190631 > TRACE :[recvThread] >> Recv Packet!
15:40:39.190646 > TRACE :[make_queueItem] from:3, msgid:10205001, bodylen:100
15:40:39.190779 > TRACE :[msgHandler:0] >> pop Data
15:40:39.190797 > TRACE :[On_CMD_VMS_STATISTIC] phone:2492,calling_number:0116858962,   start_time:2007-08-24 15:39:36,end_time:2007-08-24 15:40:39,tel_time:00:01:03,in_out:1,type:1
15:40:39.190816 > TRACE :[db_insert] query(insert into CALLUSE(phone, calling_number, start_time, end_time, tel_time, in_out, call_type) values('2492','0116858962','2007-08-24 15:39:36','2007-08-24 15:40:39','00:01:03',1, 1)) size(181)
15:40:39.190889 > TRACE :[db_insert] mysql Alive!!
15:40:39.270166 > ERROR :[db_insert] Error['CALLUSE' 테이블의 부정확한 키 존재. 수정하시오!(1034)]
15:40:39.270212 > TRACE :[On_CMD_VMS_STATISTIC] Success!!!
15:40:40.210552 > TRACE :[ep_client.c.230] recvEpoint() iLen(116)
15:40:40.210575 > TRACE :[recvThread] >> Recv Packet!
15:40:40.210590 > TRACE :[make_queueItem] from:3, msgid:10205001, bodylen:100
15:40:40.210619 > TRACE :[msgHandler:0] >> pop Data
15:40:40.210635 > TRACE :[On_CMD_VMS_STATISTIC] phone:4573,calling_number:0318287821,   start_time:2007-08-24 15:39:55,end_time:2007-08-24 15:40:40,tel_time:00:00:45,in_out:1,type:1
15:40:40.210654 > TRACE :[db_insert] query(
insert into CALLUSE(phone, calling_number, start_time, end_time, tel_time, in_out, call_type)
values('4573','0318287821','2007-08-24 15:39:55','2007-08-24 15:40:40','00:00:45',1, 1);
) size(181)
15:40:40.210726 > TRACE :[db_insert] mysql Alive!!
15:40:40.210958 > ERROR :[db_insert] Error[중복된 입력 값 '233642': key 1(1062)]
15:40:40.210979 > TRACE :[On_CMD_VMS_STATISTIC] Success!!!
15:40:51.990640 > TRACE :[ep_client.c.230] recvEpoint() iLen(116)
15:40:51.990666 > TRACE :[recvThread] >> Recv Packet!
15:40:51.990681 > TRACE :[make_queueItem] from:3, msgid:10205001, bodylen:100
15:40:51.990792 > TRACE :[msgHandler:0] >> pop Data
15:40:51.990810 > TRACE :[On_CMD_VMS_STATISTIC] phone:4936,calling_number:0226580157,   start_time:2007-08-24 15:40:37,end_time:2007-08-24 15:40:51,tel_time:00:00:14,in_out:1,type:1
15:40:51.990830 > TRACE :[db_insert] query(insert into CALLUSE(phone, calling_number, start_time, end_time, tel_time, in_out, call_type) values('4936','0226580157','2007-08-24 15:40:37','2007-08-24 15:40:51','00:00:14',1, 1)) size(181)
15:40:51.990906 > TRACE :[db_insert] mysql Alive!!
15:40:51.991146 > ERROR :[db_insert] Error[중복된 입력 값 '233642': key 1(1062)]
15:40:51.991168 > TRACE :[On_CMD_VMS_STATISTIC] Success!!!
15:40:53.620605 > TRACE :[ep_client.c.230] recvEpoint() iLen(116)
15:40:53.620626 > TRACE :[recvThread] >> Recv Packet!
15:40:53.620641 > TRACE :[make_queueItem] from:3, msgid:10205001, bodylen:100
15:40:53.620747 > TRACE :[msgHandler:0] >> pop Data

 

댓글목록

등록된 댓글이 없습니다.

전체 56
게시물 검색
MySql 목록
번호 제목 글쓴이 조회 날짜
36 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4081 12-18
35 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3909 12-18
34 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3665 12-18
33 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3646 11-10
32 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3810 07-29
31 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3965 06-20
30 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4351 03-28
29 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4311 08-17
28 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4617 08-16
27 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4304 08-16
26 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9820 05-07
25 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3996 08-10
24 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5055 08-03
23 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4079 08-03
22 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4715 07-30
21 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 3961 07-27
20 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4013 03-10
19 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4391 03-05
18 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4059 03-05
17 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4042 03-04