これは、それらを整理するために私が使用するノディスクリプトです。先頭のファイル名を変更して実行します。詳細をCSV形式で出力するので、簡単に操作できます(注意、CSVファイルの2行目はゴミなので削除してください)。あなたが持っているファイルがまったく同じ形式であるかどうかは確認できませんが、うまくいけば、これで遊んで必要なものを整理できます.
<?php
$handle = fopen('C:\\somelocation\\mysql-slow.log', "rb");
$fp = fopen('someoutputfile.csv', 'w');
$inline = '';
$inline = fgets($handle, 8192);
$OutLine = array();
$OutLine['Time'] = 'Time';
$OutLine['Timestamp'] = 'Timestamp';
$OutLine['User'] = 'User';
$OutLine['Query_time'] = 'Query_time';
$OutLine['Lock_time'] = 'Lock_time';
$OutLine['Rows_sent'] = 'Rows_sent';
$OutLine['Rows_examined'] = 'Rows_examined';
$OutLine['Database'] = 'Database';
$OutLine['SqlOut'] = 'SqlOut';
WriteOut($fp, $OutLine);
$OutLine = array();
$OutLine['Time'] = '';
$OutLine['Timestamp'] = '';
$OutLine['User'] = '';
$OutLine['Query_time'] = '';
$OutLine['Lock_time'] = '';
$OutLine['Rows_sent'] = '';
$OutLine['Rows_examined'] = '';
$OutLine['Database'] = '';
$OutLine['SqlOut'] = '';
$PossibleUse = true;
$TimeTriggeredOut = true;
$CurrentTime = '';
$CurrentDatabase = '';
while (!feof($handle))
{
switch (true)
{
case substr($inline, 0, 8) == '# Time: ' :
WriteOut($fp, $OutLine);
$PossibleUse = true;
$Timings = explode(': ', $inline);
$CurrentTime = $Timings[1];
$OutLine = array();
$OutLine['Time'] = $CurrentTime;
$OutLine['Timestamp'] = '';
$OutLine['User'] = '';
$OutLine['Query_time'] = '';
$OutLine['Lock_time'] = '';
$OutLine['Rows_sent'] = '';
$OutLine['Rows_examined'] = '';
$OutLine['Database'] = $CurrentDatabase;
$OutLine['SqlOut'] = '';
$TimeTriggeredOut = true;
break;
case substr($inline, 0, 6) == '# User' :
if (!$TimeTriggeredOut)
{
WriteOut($fp, $OutLine);
$PossibleUse = true;
$OutLine = array();
$OutLine['Time'] = $CurrentTime;
$OutLine['Timestamp'] = '';
$OutLine['User'] = '';
$OutLine['Query_time'] = '';
$OutLine['Lock_time'] = '';
$OutLine['Rows_sent'] = '';
$OutLine['Rows_examined'] = '';
$OutLine['Database'] = $CurrentDatabase;
$OutLine['SqlOut'] = '';
}
$OutLine['User'] = $inline;
$TimeTriggeredOut = false;
break;
case substr($inline, 0, 12) == '# Query_time' :
$Timings = explode(' ', $inline);
//print_r($Timings);
$OutLine['Query_time'] = $Timings[2];
$OutLine['Lock_time'] = $Timings[5];
$OutLine['Rows_sent'] = $Timings[7];
$OutLine['Rows_examined'] = $Timings[10];
$PossibleUse = true;
break;
case substr($inline, 0, 14) == 'SET timestamp=' :
$Timings = explode('=', $inline);
$OutLine['Timestamp'] = $Timings[1];
$PossibleUse = true;
break;
case $PossibleUse AND substr($inline, 0, 4) == 'use ' :
$Timings = explode(' ', $inline);
$CurrentDatabase = $Timings[1];
$OutLine['Database'] = $CurrentDatabase;
$PossibleUse = false;
break;
default;
$OutLine['SqlOut'] .= $inline;
}
$inline = fgets($handle, 8192);
}
fclose($fp);
fclose($handle);
function WriteOut($fp, $OutLine)
{
foreach($OutLine as &$aOutLine)
{
$aOutLine = str_replace("\n", " ", $aOutLine);
$aOutLine = str_replace("\r", " ", $aOutLine);
$aOutLine = str_replace("\t", " ", $aOutLine);
}
fputcsv($fp, $OutLine);
}
?>