문제
MySQL에서 마지막으로 실행 된 쿼리의 실행 시간을 얻는 방법이 있습니까?
해결책
MySQL은 a 제작자 프로파일 러. 발행하여 프로파일 링을 활성화 할 수 있습니다 set profiling=1;
그리고 사용 show profiles;
실행 시간을 얻으려면.
다른 팁
PHP를 사용하는 경우 .. 쿼리 전에 마이크로 타임 ()을 사용하여 쿼리 후 쿼리가 실행하는 데 걸리는 시간을 알아낼 수 있습니다.
$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';
제휴하지 않습니다 StackOverflow