質問

mysqlで最後に実行されたクエリの実行時間を取得する方法はありますか?

役に立ちましたか?

解決

mysqlには組み込みプロファイラーがあります。 set profiling = 1; を発行してプロファイリングを有効にし、 show profiles; を使用して実行時間を取得します。

他のヒント

PHPを使用している場合..クエリの前とクエリの後にmicrotime()を使用して、クエリの実行にかかった時間を計算できます。

$sql_query='SELECT * FROM table';
$msc=microtime(true);
$mysql_query($sql_query);
$msc=microtime(true)-$msc;
echo $msc.' seconds'; // in seconds
echo ($msc*1000).' milliseconds'; // in millseconds

試してみてください...

mysql_query("SET profiling = 1;");
if (mysql_errno()) { die( "ERROR ".mysql_errno($link) . ": " . mysql_error($link) ); }

/* It goes without saying that this is your actual query that you want to measure the execution time of */
$query="SELECT some_field_name FROM some_table_name";
$result = mysql_query($query);
if (mysql_errno()) { die( "ERROR ".mysql_errno($link) . ": " . mysql_error($link) ); }

$exec_time_result=mysql_query("SELECT query_id, SUM(duration) FROM information_schema.profiling GROUP BY query_id ORDER BY query_id DESC LIMIT 1;");
if (mysql_errno()) { die( "ERROR ".mysql_errno($link) . ": " . mysql_error($link) ); }
$exec_time_row = mysql_fetch_array($exec_time_result);

echo "<p>Query executed in ".$exec_time_row[1].' seconds';
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top