スロークエリログには以下のような値が出力される。
# Time: 180307 14:34:31
# Query_time: 705.135178 Lock_time: 0.000077 Rows_sent: 100 Rows_examined: 1046531642
Query_time |
クエリの実行時間(単位:秒) |
|
Lock_time |
クエリの実行が開始されるまでの時間。他のスレッドのロックの待ち時間 |
The time spent waiting for table locks. This value is computed in microseconds but normalized to picoseconds for easier comparison with other Performance Schema timers. |
Rows_sent |
文の実行中にストレージエンジンから読み取られた行の数 |
The number of rows returned by the statement. |
Rows_examined |
操作対象となった行数 |
The number of rows read from storage engines during statement execution. |
参考:mysql
https://dev.mysql.com/doc/refman/5.6/en/events-statements-current-table.html
参考:stackoverFlow
https://stackoverflow.com/questions/19036176/how-to-interpret-slow-query-log-information-generated-by-mysql
■MySQLのコンソールから動的に設定する
スロークエリログを出力する設定になっているか確認する
|
MariaDB [(none)]> show variables like 'slow%'; +---------------------+----------------------+ | Variable_name | Value | +---------------------+----------------------+ | slow_launch_time | 2 | | slow_query_log | ON | | slow_query_log_file | xxx-slow.log | +---------------------+----------------------+ 3 rows in set (0.00 sec) |
■上記slow_query_log がOFFになっているとスロークエリの出力は行われない。
以下のコマンドを実行する。
|
MariaDB [(none)]> set global slow_query_log_file = '/var/lib/mysql/xxx-slow.log'; MariaDB [(none)]> set global long_query_time = 0.4; MariaDB [(none)]> set global slow_query_log = ON; |
slow_query_logがONのとき、long_query_time( 上記では0.4秒)を超える場合はスロークエリとして出力される。
変更されているかを確認する場合は、一旦コンソールを抜けて、再度入り直すと反映が確認できる。
■以下で閾値を確認出来る。
|
MariaDB [(none)]> show variables like 'long%'; +-----------------+----------+ | Variable_name | Value | +-----------------+----------+ | long_query_time | 0.400000 | +-----------------+----------+ 1 row in set (0.00 sec) |
毎回忘れるので備忘録
CakePHP3でDateTimeを使用する場合は、namespaceの関係で
エラーとなる。なので、以下のように書くと良い。
例:UTCからJSTへの変換サンプル
|
//UTC → JST $time = new \DateTime(); $time->setTimestamp($utc)->setTimezone(new \DateTimeZone('Asia/Tokyo')); return $time->format($format); |
Eclipseの矩形選択モード
Macの場合、ショートカットはALT+Command+Aです。
もう一回押すと通常モードとなります。
インデントをやり直すときなど、選択して消せるので
とても便利!
If I wasn't hard, I wouldn't be alive. If I couldn't ever be gentle, I wouldn't deserve to be alive.