-
-
Save nanasess/ac68ec0bdb46c25878ffa1513256c484 to your computer and use it in GitHub Desktop.
mysqldumpslow to csv for MySQL 5.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#how to use, mysqldumpslow mysql-slow.log > hoge | |
# php MysqldumpslowResult2Csv hoge > hoge.csv | |
$log_filename = $argv[1]; | |
echo 'SQL, Count, Time, Time(total), Lock, Lock(total), Rows_sent, Rows_sent(total), Rows_examined, Rows_examined(totao), Src'."\n"; | |
if (file_exists($log_filename)) | |
{ | |
$contents = file_get_contents($log_filename); | |
$queries = preg_split('/\n{2,}/', $contents); | |
foreach ($queries as $query) | |
{ | |
if (!$query) | |
{ | |
continue; | |
} | |
$line = array(); | |
$sql = preg_split('/\n /', $query); | |
$information = array_shift($sql); | |
preg_match('/^Count: (\d+) Time=(\d+\.\d{2})s \((\d+)s\) Lock=(\d+\.\d{2})s \((\d+)s\) Rows_sent=(\d+\.\d) \((\d+)\), Rows_examined=(\d+\.\d) \((\d+)\), (.*)/', $information, $line); | |
array_shift($line); | |
array_unshift($line, sprintf('"%s"', implode(' ', $sql))); | |
echo implode(',', $line)."\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment