mariadb-check 명령어: 테이블 자동 복구

mariadb-check 명령어는 여러 테이블을 검사, 복구, 분석 및 최적화 할 수 있는 유지 관리 도구입니다. mariadb-check은 myisamchk 및 aria_chk과 다르게 서버에서 MariaDB가 실행 중이어야 합니다.

mariadb-check 명령어 mysqlcheck 명령어와 동일한 명령어입니다. 10.5 이전 버전에서는 클라이언트에서 호출했으며, 기본 사용 방법은 다음과 같습니다.

✅ mariadb-check 명령어 기본 사용법

ll /usr/bin/mariadb-check
mariadb-check -옵션 데이터베이스 or(&) 테이블

✅ mariadb-check 옵션

◻️–help 옵션

사용 옵션을 포함한 항목은 –help 옵션으로 확인할 수 있습니다.

mariadb-check --help

mariadb-check from 11.3.2-MariaDB, client 2.8 for Linux (x86_64)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

This program can be used to CHECK (-c, -m, -C), REPAIR (-r), ANALYZE (-a),
or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be
used at the same time. Not all options are supported by all storage engines.
The options -c, -r, -a, and -o are exclusive to each other, which
means that the last option will be used, if several was specified.

The option -c (--check) will be used by default, if none was specified.
You can change the default behavior by making a symbolic link, or
copying this file somewhere with another name, the alternatives are:
mysqlrepair:   The default option will be -r
mysqlanalyze:  The default option will be -a
mysqloptimize: The default option will be -o

Usage: mariadb-check [OPTIONS] database [tables]
OR     mariadb-check [OPTIONS] --databases DB1 [DB2 DB3...]
Please consult the MariaDB Knowledge Base at
https://mariadb.com/kb/en/mysqlcheck for latest information about
this program.

Default options are read from the following files in the given order:
/etc/my.cnf ~/.my.cnf 
The following groups are read: mysqlcheck mariadb-check client client-server client-mariadb
The following options may be given as the first argument:
--print-defaults          Print the program argument list and exit.
--no-defaults             Don't read default options from any option file.
The following specify which files/extra groups are read (specified before remaining options):
--defaults-file=#         Only read default options from the given file #.
--defaults-extra-file=#   Read this file after the global files are read.
--defaults-group-suffix=# Additionally read default groups with # appended as a suffix.

  -A, --all-databases Check all the databases. This is the same as --databases
                      with all databases selected.
  -a, --analyze       Analyze given tables.
  -1, --all-in-1      Instead of issuing one query for each table, use one
                      query per database, naming all tables in the database in
                      a comma-separated list.
  --auto-repair       If a checked table is corrupted, automatically fix it.
                      Repairing will be done after all tables have been
                      checked, if corrupted ones were found.
  --character-sets-dir=name 
                      Directory for character set files.
  -c, --check         Check table for errors.
  -C, --check-only-changed 
                      Check only tables that have changed since last check or
                      haven't been closed properly.
  -g, --check-upgrade Check tables for version-dependent changes. May be used
                      with --auto-repair to correct tables requiring
                      version-dependent updates.
  --compress          Use compression in server/client protocol.
  -B, --databases     Check several databases. Note the difference in usage; in
                      this case no tables are given. All name arguments are
                      regarded as database names.
  -#, --debug[=#]     This is a non-debug version. Catch this and exit.
  --debug-check       Check memory and open file usage at exit.
  --debug-info        Print some debug info at exit.
  --default-character-set=name 
                      Set the default character set.
  --default-auth=name Default authentication client-side plugin to use.
  -F, --fast          Check only tables that haven't been closed properly.
  --fix-db-names      Fix database names.
  --fix-table-names   Fix table names.
  -f, --force         Continue even if we get an SQL error.
  -e, --extended      If you are using this option with CHECK TABLE, it will
                      ensure that the table is 100 percent consistent, but will
                      take a long time. If you are using this option with
                      REPAIR TABLE, it will force using old slow repair with
                      keycache method, instead of much faster repair by
                      sorting.
  --flush             Flush each table after check. This is useful if you don't
                      want to have the checked tables take up space in the
                      caches after the check
  -?, --help          Display this help message and exit.
  -h, --host=name     Connect to host.
  -m, --medium-check  Faster than extended-check, but only finds 99.99 percent
                      of all errors. Should be good enough for most cases.
  --write-binlog      Log ANALYZE, OPTIMIZE and REPAIR TABLE commands. Use
                      --skip-write-binlog when commands should not be sent to
                      replication slaves.
                      (Defaults to on; use --skip-write-binlog to disable.)
  -o, --optimize      Optimize table.
  -p, --password[=name] 
                      Password to use when connecting to server. If password is
                      not given, it's solicited on the tty.
  -Z, --persistent    When using ANALYZE TABLE use the PERSISTENT FOR ALL
                      option.
  --plugin-dir=name   Directory for client-side plugins.
  -P, --port=#        Port number to use for connection or 0 for default to, in
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
                      /etc/services, built-in default (3306).
  --protocol=name     The protocol to use for connection (tcp, socket, pipe).
  -q, --quick         If you are using this option with CHECK TABLE, it
                      prevents the check from scanning the rows to check for
                      wrong links. This is the fastest check. If you are using
                      this option with REPAIR TABLE, it will try to repair only
                      the index tree. This is the fastest repair method for a
                      table.
  -r, --repair        Can fix almost anything except unique keys that aren't
                      unique.
  -s, --silent        Print only error messages.
  --skip-database=name 
                      Don't process the database specified as argument
  -S, --socket=name   The socket file to use for connection.
  --ssl               Enable SSL for connection (automatically enabled with
                      other flags).
                      (Defaults to on; use --skip-ssl to disable.)
  --ssl-ca=name       CA file in PEM format (check OpenSSL docs, implies
                      --ssl).
  --ssl-capath=name   CA directory (check OpenSSL docs, implies --ssl).
  --ssl-cert=name     X509 cert in PEM format (implies --ssl).
  --ssl-cipher=name   SSL cipher to use (implies --ssl).
  --ssl-key=name      X509 key in PEM format (implies --ssl).
  --ssl-crl=name      Certificate revocation list (implies --ssl).
  --ssl-crlpath=name  Certificate revocation list path (implies --ssl).
  --tls-version=name  TLS protocol version for secure connection.
  --ssl-verify-server-cert 
                      Verify server's "Common Name" in its cert against
                      hostname used when connecting. This option is disabled by
                      default.
  --tables            Overrides option --databases (-B).
  --use-frm           When used with REPAIR, get table structure from .frm
                      file, so the table can be repaired even if .MYI header is
                      corrupted.
  -u, --user=name     User for login if not current user.
  -v, --verbose       Print info about the various stages; Using it 3 times
                      will print out all CHECK, RENAME and ALTER TABLE during
                      the check phase.
  -V, --version       Output version information and exit.
  --process-views[=name] 
                      Perform the requested operation (check or repair) on
                      views. One of: NO, YES (correct the checksum, if
                      necessary, add the mariadb-version field), UPGRADE (run
                      from mariadb-upgrade), UPGRADE_FROM_MYSQL (same as YES
                      and toggle the algorithm MERGE<->TEMPTABLE.
  --process-tables    Perform the requested operation on tables.
                      (Defaults to on; use --skip-process-tables to disable.)

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- ----------------------------------------
all-databases                     FALSE
all-in-1                          FALSE
auto-repair                       FALSE
character-sets-dir                (No default value)
compress                          FALSE
databases                         FALSE
debug-check                       FALSE
debug-info                        FALSE
default-character-set             utf8mb4
default-auth                      (No default value)
fast                              FALSE
fix-db-names                      FALSE
fix-table-names                   FALSE
force                             FALSE
extended                          FALSE
flush                             FALSE
host                              (No default value)
write-binlog                      TRUE
persistent                        FALSE
plugin-dir                        (No default value)
port                              3306
quick                             FALSE
silent                            FALSE
skip-database                     (No default value)
socket                            (No default value)
ssl                               TRUE
ssl-ca                            (No default value)
ssl-capath                        (No default value)
ssl-cert                          (No default value)
ssl-cipher                        (No default value)
ssl-key                           (No default value)
ssl-crl                           (No default value)
ssl-crlpath                       (No default value)
tls-version                       (No default value)
ssl-verify-server-cert            FALSE
use-frm                           FALSE
user                              (No default value)
process-views                     NO
process-tables                    TRUE

◻️옵션

옵션상세 옵션설명
-A--all-databases모든 데이터베이스에 있는 테이블을 검사합니다.
-a--analyze테이블을 분석합니다.
--auto-repair검사한 테이블이 손상된 경우 자동으로 복구합니다.
모든 테이블이 검사 된 후에 복구가 진행됩니다.
-c--check테이블에 오류가 있는지 검사합니다.
-C--check-only-changed마지막 확인 이후 변경된 테이블이나 제대로 닫히지 않은 테이블만 확인하는 경우
g--check-upgrade버전에 따라 달라지는 변경 사항이 있는지 테이블을 확인합니다. 버전에 따라 달라지는 업데이트가 필요한 테이블을 수정하는 데 사용할 수 있습니다 --auto-repair--fix-db-names및 --fix-table-names옵션을 자동으로 활성화합니다. 업그레이드할 때 사용합니다.
--compress클라이언트와 서버 모두 압축을 지원하는 경우, 둘 사이에 전송되는 모든 정보를 압축합니다.
-B-B,--databases여러 데이터베이스를 확인합니다. 일반적으로 mariadb-check는 첫 번째 인수를 데이터베이스 이름으로, 그 다음 인수를 테이블 이름으로 취급합니다. 이 옵션을 사용하면 테이블이 제공되지 않고 모든 이름 인수가 데이터베이스 이름으로 간주됩니다.
-#--debug[=name]출력 디버그 로그. 종종 ‘d:t:o,파일 이름’입니다.
--debug-check종료 시 메모리와 열려 있는 파일 사용량을 확인합니다.
--debug-info종료 시 일부 디버그 정보를 출력합니다.
--default-auth=plugin사용할 기본 인증 클라이언트 측 플러그인입니다.
--default-character-set=name기본 문자 집합을 설정합니다 .
-e--extended이 옵션을 와 함께 사용하는 경우 --check테이블이 100% 일관성을 유지하도록 보장하지만 시간이 오래 걸립니다. 이 옵션을 와 함께 사용하는 경우 --repair훨씬 빠른 정렬 복구 대신 이전의 느린 키캐시 복구 방법을 강제로 사용하게 됩니다.
-F--fast제대로 닫히지 않은 테이블만 확인
--flush체크 후 각 테이블을 플러시합니다. 체크한 테이블이 체크 후 캐시 공간을 차지하지 않도록 하려는 경우 유용합니다.
-f--forceSQL 오류가 발생하더라도 계속 진행합니다.
-?--help도움말 메시지를 표시하고 종료합니다.
-h name name--host=name주어진 호스트에 연결합니다.
-m--medium-checkextended-check보다 빠르지만 모든 오류의 99.99%만 찾아냅니다.
대부분의 경우에 충분할 것입니다.
-o--optimize테이블을 최적화합니다.
-p--password[=name]서버에 연결할 때 사용할 비밀번호입니다. 짧은 옵션 형식( -p)을 사용하는 경우 옵션과 비밀번호 사이에 공백을 둘 수 없습니다. 명령줄에서 --password또는 
-p옵션 뒤에 비밀번호 값을 생략하면 mariadb-check에서 비밀번호를 묻습니다. 명령줄에서 비밀번호를 지정하는 것은 안전하지 않은 것으로 간주해야 합니다. 옵션 파일을 사용하면 명령줄에서 비밀번호를 제공하지 않아도 됩니다.
-Z--persistentANALYZE TABLE( )을 사용할 때 --analyzePERSISTENT FOR ALL 옵션을 사용하여
이 테이블에 대한 엔진 독립 통계를 강제로 업데이트합니다. 
[MariaDB 10.1.10 부터 추가됨]
--plugin-dir클라이언트 측 플러그인을 위한 디렉토리입니다.
-P num--port=num연결에 사용할 포트 번호 또는 기본값인 0(우선순위에 따라 my.cnf, $MYSQL_TCP_PORT, /etc/services, 기본 제공 기본값[3306]).
--process-tables요청된 작업(확인, 복구, 분석, 최적화)을 테이블에서 수행합니다. 기본적으로 활성화되어 있습니다. --skip-process-tables비활성화하는 데 사용합니다.
--process-views[=val]요청된 작업을 수행합니다( CHECK VIEW 또는 REPAIR VIEW 만 ). 가능한 값은 NO, YES(필요한 경우 체크섬을 수정하고 mariadb-version 필드를 추가), UPGRADE_FROM_MYSQL(YES와 동일하고 알고리즘 MERGE<->TEMPTABLE을 전환)입니다.
--protocol=name서버에 연결하는 데 사용할 연결 프로토콜(tcp, 소켓, 파이프, 메모리). 다른 연결 매개변수로 인해 원하는 프로토콜이 아닌 다른 프로토콜이 사용될 때 유용합니다.
-q,--quick이 옵션을 CHECK TABLE과 함께 사용하는 경우, 검사가 잘못된 링크를 검사하기 위해 행을 스캔하지 못하게 합니다. 이것은 가장 빠른 검사입니다. 이 옵션을 REPAIR TABLE과 함께 사용하는 경우, 인덱스 트리만 복구하려고 시도합니다. 이것은 테이블에 대한 가장 빠른 복구 방법입니다.
-r--repair고유하지 않은 고유 키를 제외하고 거의 모든 것을 수정할 수 있습니다.
--shared-memory-base-name로컬 서버에 공유 메모리를 사용하여 Windows 연결에 사용할 공유 메모리 이름(옵션으로 시작 --shared-memory). 대소문자 구분.
-s-s--silent오류 메시지만 인쇄합니다.
--skip-database인수로 지정된 데이터베이스(대소문자 구분)를 처리하지 않습니다.
-S name--socket=name로컬호스트에 연결하는 경우 사용할 Unix 소켓 파일이거나 Windows에서는 사용할 명명된 파이프의 이름입니다.
--sslTLS를 활성화합니다 . 특정 다른 TLS 옵션이 설정된 경우 이 옵션을 설정하지 않아도 TLS가 활성화됩니다. MariaDB 10.2 부터 이 옵션은 기본적으로 서버 인증서 확인을--ssl 활성화하지 않습니다 . 서버 인증서를 확인하려면 사용자가 옵션을 지정해야 합니다.--ssl-verify-server-cert
--ssl-ca=nameTLS 에 사용할 신뢰할 수 있는 인증 기관(CA)에 대한 하나 이상의 X509 인증서를 포함해야 하는 PEM 파일에 대한 경로를 정의합니다 . 이 옵션을 사용하려면 상대 경로가 아닌 절대 경로를 사용해야 합니다. 자세한 내용은 보안 연결 개요: 인증 기관(CA)을 참조하세요 . 이 옵션은 --ssl옵션을 의미합니다.
--ssl-capath=nameTLS 에 사용할 신뢰할 수 있는 인증 기관(CA)에 대한 X509 인증서가 각각 하나씩 포함되어야 하는 하나 이상의 PEM 파일이 들어 있는 디렉토리 경로를 정의합니다 . 이 옵션을 사용하려면 상대 경로가 아닌 절대 경로를 사용해야 합니다. 이 옵션에서 지정한 디렉토리는 openssl rehash 명령을 통해 실행해야 합니다. 자세한 내용은 보안 연결 개요: 인증 기관(CA)을 참조하세요 . 이 옵션은 클라이언트가 OpenSSL 또는 yaSSL로 빌드된 경우에만 지원됩니다. 클라이언트가 GnuTLS 또는 Schannel로 빌드된 경우 이 옵션은 지원되지 않습니다. 어떤 플랫폼에서 어떤 라이브러리가 사용되는지에 대한 자세한 내용은 MariaDB에서 사용하는 TLS 및 암호화 라이브러리를 참조하세요 . 이 옵션은 해당 --ssl옵션을 의미합니다.
--ssl-cert=nameTLS 에 사용할 X509 인증서 파일에 대한 경로를 정의합니다 . 이 옵션은 상대 경로가 아닌 절대 경로를 사용해야 합니다. 이 옵션은 옵션을 의미합니다 --ssl.
--ssl-cipher=nameTLS 에 사용할 수 있는 허용된 암호 또는 암호 모음 목록 . 이 옵션은 --ssl옵션을 의미합니다.
--ssl-crl=nameTLS 에 사용할 하나 이상의 해지된 X509 인증서를 포함해야 하는 PEM 파일에 대한 경로를 정의합니다 . 이 옵션을 사용하려면 상대 경로가 아닌 절대 경로를 사용해야 합니다. 자세한 내용은 보안 연결 개요: 인증서 해지 목록(CRL)을 참조하세요 . 이 옵션은 클라이언트가 OpenSSL 또는 Schannel로 빌드된 경우에만 지원됩니다. 클라이언트가 yaSSL 또는 GnuTLS로 빌드된 경우 이 옵션은 지원되지 않습니다. 어떤 플랫폼에서 어떤 라이브러리가 사용되는지에 대한 자세한 내용은 MariaDB에서 사용하는 TLS 및 암호화 라이브러리를 참조하세요.
--ssl-crlpath=nameTLS 에 사용할 해지된 X509 인증서가 하나씩 들어 있는 하나 이상의 PEM 파일이 들어 있는 디렉토리 경로를 정의합니다 . 이 옵션을 사용하려면 상대 경로가 아닌 절대 경로를 사용해야 합니다. 이 옵션에서 지정한 디렉토리는 openssl rehash 명령을 통해 실행해야 합니다. 자세한 내용은 보안 연결 개요: 인증서 해지 목록(CRL)을 참조하세요 . 이 옵션은 클라이언트가 OpenSSL로 빌드된 경우에만 지원됩니다. 클라이언트가 yaSSL, GnuTLS 또는 Schannel로 빌드된 경우 이 옵션은 지원되지 않습니다. 어떤 플랫폼에서 어떤 라이브러리가 사용되는지에 대한 자세한 내용은 MariaDB에서 사용하는 TLS 및 암호화 라이브러리를 참조하세요 .
--ssl-key=nameTLS 에 사용할 개인 키 파일에 대한 경로를 정의합니다 . 이 옵션은 상대 경로가 아닌 절대 경로를 사용해야 합니다. 이 옵션은 옵션을 의미합니다 --ssl.
--ssl-verify-server-cert서버 인증서 검증을 활성화합니다 . 이 옵션은 기본적으로 비활성화되어 있습니다.
--tables옵션 뒤에 오는 모든 이름 인수를 테이블 이름으로 간주하도록 옵션을 --databases재정의 합니다 .-B
--use-frmMyISAM 테이블의 복구 작업의 경우 .frm 파일에서 테이블 구조를 가져오면 .MYI 헤더가 손상된 경우에도 테이블을 복구할 수 있습니다.
-u,--user=name현재 사용자가 아닌 경우 로그인을 위한 사용자입니다.
-v--verbose다양한 단계에 대한 정보를 인쇄합니다. 이 옵션을 여러 번 제공하여 더 많은 정보를 얻을 수 있습니다. 아래의 mariadb-check 및 verbose 를 참조하세요 .
-V--version버전 정보를 출력하고 종료합니다.
--write-binlog바이너리 로그 에 ANALYZE, OPTIMIZE 및 REPAIR TABLE 명령을 작성합니다 . 기본적으로 활성화되어 있습니다. --skip-write-binlog명령을 복제 슬레이브에 보내면 안 될 때 사용합니다.
옵션상세 옵션설명
참조: mariadb-check 페이지

◻️자주 사용하는 옵션

✅ mariadb-check 명령어로 테이블 분석 및 자동 복구

테이블 최적화인 -o 옵션을 사용하니 “Table does not support optimize, doing recreate + analyze instead”라면서 테이블 최적화를 진행하는 대신 재 생성과 분석을 수행한다는 메시지가 나와 모든 데이터베이스 검사&분석, 그리고 자동 복구 옵션으로 명령어를 실행해 봤습니다.

mariadb-check  -Aa  --auto-repair

✅ crontab 등록하기

테이블 분석 및 자동 복구 설정을 crontab에 등록합니다.

~]# crontab -e

30 04 * * * mariadb-check  -Aa  --auto-repair
# 매일 4시 30분에 실행 설정 테이블 분석 및 자동 복구 설정#
마리아디비(MariaDB) 로고

Similar Posts