LoginSignup
1
0

More than 1 year has passed since last update.

MySQLで調査時によく使う確認方法まとめ

Posted at

MySQL使用時、設定情報や接続情報を中に入って確認する際に、個人的によく使うものメモ。

基本

MySQL> SHOW GLOBAL VARIABLES;

で、MySQLサーバーのシステム設定値を確認できる。

MySQL> SHOW GLOBAL STATUS;

で、MySQLサーバーのステータス値を確認できる。
ここから、確認したい値をgrepする。
以下、よく使うものを記載する。

システム設定値

許可されている最大同時接続数を確認する

MySQL> SHOW GLOBAL VARIABLES like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 45    |
+-----------------+-------+
1 row in set (0.00 sec)

ちなみにAWS RDS使用時は、最大同時接続数はDBインスタンスサイズによってデフォルト値が規定されている。
参考

ステータス値

累積のDB接続数を確認する

MySQL> SHOW GLOBAL STATUS LIKE 'Conn%';
+-----------------------------------+-------+
| Variable_name                     | Value |
+-----------------------------------+-------+
| Connection_errors_accept          | 0     |
| Connection_errors_internal        | 0     |
| Connection_errors_max_connections | 0     |
| Connection_errors_peer_address    | 0     |
| Connection_errors_select          | 0     |
| Connection_errors_tcpwrap         | 0     |
| Connections                       | 47    |
+-----------------------------------+-------+
7 rows in set (0.00 sec)

のうち、Connections の値が累積でのDB接続数。

現在のDB接続数を確認する

MySQL> SHOW GLOBAL STATUS LIKE 'Threads_connected';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 11    |
+-------------------+-------+
1 row in set (0.00 sec)

その他使いそうなコマンド

現在実行されているスレッドを確認する

MySQL> SHOW PROCESSLIST;

現在オープンされているテーブルを確認する

MySQL> SHOW OPEN TABLES;

ユーザの権限を確認する

MySQL> SHOW GRANTS;

クエリで発生したエラー系

クエリで発生した警告
MySQL> SHOW WARNINGS

クエリで発生したエラー
MySQL> SHOW ERRORS;

補足

\Gを最後に付与してコマンド実行すると、出力結果横幅が広い際に見やすくなる。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0