41から始めました

文字通り41歳から始めたブログです。DB(MySQL)を使ってお仕事してるので、DB周りの話を中心に最近始めたこととかをTwitterのノリで書いています。なお、本サイトにおいて示されている見解は私個人の見解であり、所属団体や組織を代表するものではありません。

perrorコマンドって知ってる?

昨日とあるイベントに参加して知ったコマンドperrorについて

perrorとは?

公式(perror - エラーコードの説明)を参照

要するに、MySQLがエラーコードやエラー番号を出力するんだけど、そのエラーの意味がこのツールで分かりますというもの。

使い方

MySQL(クライアントではない)が入ってるサーバ上で

perror [エラーコード|エラー番号]

を叩くだけ。

イメージ

# perror 1153
MySQL error code 1153 (ER_NET_PACKET_TOO_LARGE): Got a packet bigger than 'max_allowed_packet' bytes
# perror 1064
MySQL error code 1064 (ER_PARSE_ERROR): %s near '%-.80s' at line %d

エラーコードを二個まとめて書いてもいい

# perror 1064 1153
MySQL error code 1064 (ER_PARSE_ERROR): %s near '%-.80s' at line %d
MySQL error code 1153 (ER_NET_PACKET_TOO_LARGE): Got a packet bigger than 'max_allowed_packet' bytes

前述の公式を読めばオプションについても書いてあるけど、一応記載。

オプション 説明
--help, --info, -I, -? ヘルプメッセージを表示して終了します。
--ndb MySQL Cluster エラーコードのエラーメッセージを出力します。
--silent, -s サイレントモード。エラーメッセージのみ出力します。
--verbose, -v 冗長モード。エラーコードおよびメッセージを出力します。これはデフォルトの動作です。
--version, -V バージョン情報を表示して終了します。

MySQLがイミフなエラーコード返して来たら、とりあえずperror叩いてみると良いことあるかも。

おまけ

perror と叩くだけだとヘルプが出る。 その際、ヘルプにオプションとして-aというのがMySQL5.5の場合はあるんだけど、5.6.3から無くなってる。

% perror                                                                                                                                                                                                                          [10:06:27]
perror Ver 2.11, for Linux (x86_64)
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL license

Print a description for a system error code or a MySQL error code.
If you want to get the error for a negative error code, you should use
-- before the first error code to tell perror that there was no more options.

Usage: perror [OPTIONS] [ERRORCODE [ERRORCODE...]]
  -?, --help          Displays this help and exits.
  -I, --info          Synonym for --help.
  -a, --all           Print all the error messages and the number. Deprecated,
                      will be removed in a future release.
  -s, --silent        Only print the error message.
  -v, --verbose       Print error code and message (default).
                      (Defaults to on; use --skip-verbose to disable.)
  -V, --version       Displays version information and exits.

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- ----------------------------------------
all                               FALSE
verbose                           TRUE
% perror                                                                                                                                                                                                                          [10:06:55]
perror Ver 2.11, for Linux (x86_64)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Print a description for a system error code or a MySQL error code.
If you want to get the error for a negative error code, you should use
-- before the first error code to tell perror that there was no more options.

Usage: perror [OPTIONS] [ERRORCODE [ERRORCODE...]]
  -?, --help          Displays this help and exits.
  -I, --info          Synonym for --help.
  -s, --silent        Only print the error message.
  -v, --verbose       Print error code and message (default).
                      (Defaults to on; use --skip-verbose to disable.)
  -V, --version       Displays version information and exits.

Variables (--variable-name=value)
and boolean options {FALSE|TRUE}  Value (after reading options)
--------------------------------- ----------------------------------------
verbose                           TRUE

こんな感じのこと書いてる。

The undocumented --all option for perror has been removed. Also, perror no longer displays messages for BDB error codes.

https://dev.mysql.com/doc/relnotes/mysql/5.6/en/news-5-6-3.html

じゃ、-a | --all ってどんなオプションなの?というと、こんな感じ。

% perror -a                                                                                                                                                                                                                       
 80 = Accessing a corrupted shared library
 81 = .lib section in a.out corrupted
 82 = Attempting to link in too many shared libraries
 83 = Cannot exec a shared library directly
 84 = Invalid or incomplete multibyte or wide character
 85 = Interrupted system call should be restarted
 86 = Streams pipe error
 87 = Too many users
 88 = Socket operation on non-socket
 89 = Destination address required
 90 = Message too long
 91 = Protocol wrong type for socket
 92 = Protocol not available
 93 = Protocol not supported
 94 = Socket type not supported
 95 = Operation not supported
 96 = Protocol family not supported
 97 = Address family not supported by protocol
 98 = Address already in use
 99 = Cannot assign requested address
100 = Network is down
101 = Network is unreachable
102 = Network dropped connection on reset
103 = Software caused connection abort
104 = Connection reset by peer
105 = No buffer space available
106 = Transport endpoint is already connected
107 = Transport endpoint is not connected
108 = Cannot send after transport endpoint shutdown
109 = Too many references: cannot splice
110 = Connection timed out
111 = Connection refused
112 = Host is down
113 = No route to host
114 = Operation already in progress
115 = Operation now in progress
116 = Stale NFS file handle
117 = Structure needs cleaning
118 = Not a XENIX named type file
119 = No XENIX semaphores available
120 = Is a named type file
121 = Remote I/O error
122 = Disk quota exceeded
123 = No medium found
124 = Wrong medium type
125 = Operation canceled
126 = Required key not available
127 = Key has expired
128 = Key has been revoked
129 = Key was rejected by service
130 = Owner died
131 = State not recoverable
-30999 = DB_INCOMPLETE: Sync didn't finish
-30998 = DB_KEYEMPTY: Key/data deleted or never created
-30997 = DB_KEYEXIST: The key/data pair already exists
-30996 = DB_LOCK_DEADLOCK: Deadlock
-30995 = DB_LOCK_NOTGRANTED: Lock unavailable
-30994 = DB_NOSERVER: Server panic return
-30993 = DB_NOSERVER_HOME: Bad home sent to server
-30992 = DB_NOSERVER_ID: Bad ID sent to server
-30991 = DB_NOTFOUND: Key/data pair not found (EOF)
-30990 = DB_OLD_VERSION: Out-of-date version
-30989 = DB_RUNRECOVERY: Panic return
-30988 = DB_VERIFY_BAD: Verify failed; bad format

便利そうに見えたけど、全てを表示しているわけじゃなさそうだし、意味ないな…。 昔の名残か?