subject MySQL DB 가 깨졌을때 살리는법
author 관리자 date 2003-11-17 hit 203 HIT
http://ilinuxbay.com/contentChannel/article.php?scol_serial=1894&aca_idx=4

어느날 아침 로긴이 안되거나 혹은 게시판에서 데이터 베이스 엑세스를 할수 없습니다.. 이런 메세지를 볼수 있다. 난감하기 그지 없다... 어떻게 극복을 할것인가... ?
데이터 베이스는 항상 깨지기 마련이다. 1년은 운영한다면.. 적어도 1~2회 정도는 화일을 열수 없습니다.


에러 메세지 :
ERROR 1016: Can't open file: 'xxxxxx.MYD'. (errno: 145)

만약 /usr/local/mysql/var/데이터 베이스에 들어 가면 각각의 부분에 대하여
*.FRM : 테이블 정보
*.MYI : 인덱스 정보
*.MYD : 데이타 정보

[ root@ilinuxbay ]# /usr/local/mysql/bin/myisamchk sessions.*
myisamchk: error: 'sessions.MYD' is not a MyISAM-table

---------

Checking MyISAM file: sessions.MYI
Data records: 6 Deleted blocks: 6
myisamchk: warning: Table is marked as crashed
- check file-size
- check key delete-chain
- check record delete-chain
myisamchk: warning: Not used space is supposed to be: 896 but is: 624
myisamchk: error: record delete-link-chain corrupted
- check index reference
- check data record references index: 1
myisamchk: error: Found 4 keys of 6
- check record links
myisamchk: error: Record-count is not ok; is 4 Should be: 6
myisamchk: warning: Found 4 deleted blocks Should be: 6
myisamchk: warning: Found 8 parts Should be: 11 parts
MyISAM-table 'sessions.MYI' is corrupted
Fix it using switch "-r" or "-o"

---------

누가 지웠나.. 혹은 화일이 없는 경우 다음과 같은 명령어를 이용 확인 복구를 할 수 있다.


]#myisamchk 옵션을 보면

# -r -o로 복구가 안되면다 -f 옵션을 이용한다.
-f, --force Overwrite old temporary files.

#복구
-r, --recover Can fix almost anything except unique keys that aren't unique.

#안전하게 복구
-o, --safe-recover Uses old recovery method; Slower than '-r' but can
handle a couple of cases where '-r' reports that it
can't fix the data file.

#데이터 정렬 및 속도 증가 -R1 저도 주면 될듯 싶네요
-R, --sort-records=#
Sort records according to an index. This makes your
data much more localized and may speed up things

일반적으로 -r 을 기본으로 사용하며 대상 화일은 * 확장자를 잡으면 된다.
그럼 복구를 해보자.


[ root@ilinuxbay ]# /usr/local/mysql/bin/myisamchk -r sessions.*
myisamchk: error: 'sessions.MYD' is not a MyISAM-table

---------

- recovering (with sort) MyISAM-table 'sessions.MYI'
Data records: 6
- Fixing index 1
Data records: 4

---------

혹 구버전인 경우 isamchk 명령어를 이용 복구 가능합니다. 가능한 데이터베이스를 정지하고 하세요.
그럼.. 무운을 빕니다. 전 복구 했어요.


목록보기
17  조인 쿼리 예제  2006-05-04 164
16  [쿼리문] 데이타 파일에서 자료 읽어오기 (load data)  2005-09-19 91
15  두근두근만화방 로그변환 DB 업데이트 소스  2005-09-16 146
14  데이타 덤프 와 복구  2006-10-21 239
13  원격 접속 열기  2006-05-26 240
12  MySql 통합 접속툴 - phpMyAdmin-2.8.0.3 설치  2006-04-24 260
11  다양한 쿼리 예제들  2005-10-24 202
10  Group by 사용 예제  2004-10-04 346
9  중복행체크.. Distinct 사용..  2004-10-04 311
 MySQL DB 가 깨졌을때 살리는법  2003-11-17 203
7  MySQL 복구하기  2003-11-17 250
6  MySQL 유저 등록하기 (원격접속포함)  2003-11-17 199
5  MySQL 데이타를 text 혹은 excel 파일로 받는 법  2003-11-17 107
4  필드 최적화 체크 방법  2003-11-17 88
3  초기 루트 사용자 설정  2003-11-17 83
1 2