怎样获得mysql处理一个sql文件所用的毫秒数?

比如:source schema.sql; schema.sql中含有超过100条insert命令(所以profile基本上就用不着了),我要怎么才能知道处理这个文件用了多少毫秒呢?

阅读 4.3k
1 个回答

你没办法把默认的那个显示时间改成毫秒 ...

如果想要更精确的查询时间 ... 你需要开启 Profile ... 方法如下 ...

mysql> set profiling=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select * from bigtable;
29121487 rows in set (0.00 sec)

mysql> show profiles;
+----------+------------+--------------------+
| Query_ID | Duration   | Query              |
+----------+------------+--------------------+
|        1 | 0.00026925 | select * from user |
+----------+------------+--------------------+
1 row in set (0.00 sec)

mysql> show profile;
+--------------------------------+----------+
| Status                         | Duration |
+--------------------------------+----------+
| starting                       | 0.000020 |
| Waiting for query cache lock   | 0.000005 |
| checking query cache for query | 0.000028 |
| checking permissions           | 0.000008 |
| Opening tables                 | 0.000019 |
| System lock                    | 0.000011 |
| init                           | 0.000033 |
| optimizing                     | 0.000006 |
| statistics                     | 0.000010 |
| preparing                      | 0.000009 |
| executing                      | 0.000004 |
| Sending data                   | 0.000078 |
| end                            | 0.000006 |
| query end                      | 0.000003 |
| closing tables                 | 0.000008 |
| freeing items                  | 0.000016 |
| logging slow query             | 0.000004 |
| cleaning up                    | 0.000005 |
+--------------------------------+----------+
18 rows in set (0.00 sec)

mysql> 

这是不错的性能分析器 ... 相关的资料也不少 ... 知道关键字之后自己看看吧 ...

推荐问题
logo
101 新手上路
子站问答
访问
宣传栏