mysql command line return execution time?

前端 未结 3 1663
陌清茗
陌清茗 2021-02-07 05:45

I\'m working on a Linux host with mysql command. I have a script that runs batch mysql commands (like mysql -e \"select...\") and I wish to summarize execution time

3条回答
  •  鱼传尺愫
    2021-02-07 06:29

    Here is the exact syntax for PHP.

    mysql_query("SET profiling = 1;");
    if (mysql_errno()) { die( "ERROR ".mysql_errno($link) . ": " . mysql_error($link) ); }
    
    $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 "

    Query executed in ".$exec_time_row[1].' seconds';

提交回复
热议问题