MySQL如何精确显示对指定数据库进行操作所用时间? 本帖最后由 Relaxing 于 2013-04-12 14:14:14 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 能在命令行中或者navicat中实现吗? 在Linux的Shell下 time是显示当前时间在Windows的CMD下 time /T是显示当前时间在MySQL下select now()是显示当前时间 select now();your sql ;select now();两次now的差 取得时间是用select now()吗?怎么把当前时间存到变量名里面呢? 在SP中可以select now() into @aa;sqlselect TIMEDIFF(now(),@aa) 顺便问一下,啥叫SP,我不太懂,难道是SQL Procedure吗? 可以在sql文件中直接这么用吗? select now() into @aa;这句可以select TIMEDIFF(now(),@aa)这句没有用过,应该可以 select now() into @aa;sqlselect now() into @bb;set @cc = @bb - @aa显示结果为0啊 会不会是select now() into @aa;sqlselect now() into @bb;set @cc = @bb - @aa里面的SQL执行时间太短了#13 的wwwwb说得应该是对的 我怀疑已经超过了SQL检测的能力范围,你可以考虑把SQL嵌入高级语言,用高级语言测试时间java好像有个System.nanotime()的函数,不知道能不能精确的纳秒.不过System.currentTimeMillis()还是可以检测到毫秒 SHOW PROFILE SHOW PROFILESmysql> SELECT @@profiling;+-------------+| @@profiling |+-------------+| 0 |+-------------+1 row in set (0.00 sec)mysql> SET profiling = 1;Query OK, 0 rows affected (0.00 sec)mysql> DROP TABLE IF EXISTS t1;Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> CREATE TABLE T1 (id INT);Query OK, 0 rows affected (0.01 sec)mysql> SHOW PROFILES;+----------+----------+--------------------------+| Query_ID | Duration | Query |+----------+----------+--------------------------+| 0 | 0.000088 | SET PROFILING = 1 || 1 | 0.000136 | DROP TABLE IF EXISTS t1 || 2 | 0.011947 | CREATE TABLE t1 (id INT) |+----------+----------+--------------------------+3 rows in set (0.00 sec)mysql> SHOW PROFILE;+----------------------+----------+| Status | Duration |+----------------------+----------+| checking permissions | 0.000040 || creating table | 0.000056 || After create | 0.011363 || query end | 0.000375 || freeing items | 0.000089 || logging slow query | 0.000019 || cleaning up | 0.000005 |+----------------------+----------+7 rows in set (0.00 sec)mysql> SHOW PROFILE FOR QUERY 1;+--------------------+----------+| Status | Duration |+--------------------+----------+| query end | 0.000107 || freeing items | 0.000008 || logging slow query | 0.000015 || cleaning up | 0.000006 |+--------------------+----------+4 rows in set (0.00 sec)mysql> SHOW PROFILE CPU FOR QUERY 2;+----------------------+----------+----------+------------+| Status | Duration | CPU_user | CPU_system |+----------------------+----------+----------+------------+| checking permissions | 0.000040 | 0.000038 | 0.000002 || creating table | 0.000056 | 0.000028 | 0.000028 || After create | 0.011363 | 0.000217 | 0.001571 || query end | 0.000375 | 0.000013 | 0.000028 || freeing items | 0.000089 | 0.000010 | 0.000014 || logging slow query | 0.000019 | 0.000009 | 0.000010 || cleaning up | 0.000005 | 0.000003 | 0.000002 |+----------------------+----------+----------+------------+ sql语句优化 MYSQL编译时出现的问题 问一下大批量数据导入到mysql mysql + ssh 为什么使用分区功能会被注释掉? PostgreSQL 大小写的问题? php5.0.4+mysql5.0+apache2.0.53乱码问题!!! 一个数据转换问题 替换mysql某个字段值里的中文 Msql查询两天内数据总数 如何在一台机器上测试mysql同步 用mysqldump导入数据库失败的问题
在Linux的Shell下 time是显示当前时间
在Windows的CMD下 time /T是显示当前时间
在MySQL下select now()是显示当前时间
your sql ;
select now();两次now的差
select now() into @aa;
sql
select TIMEDIFF(now(),@aa)
select now() into @aa;这句可以
select TIMEDIFF(now(),@aa)这句没有用过,应该可以
sql
select now() into @bb;
set @cc = @bb - @aa
显示结果为0啊
会不会是select now() into @aa;
sql
select now() into @bb;
set @cc = @bb - @aa
里面的SQL执行时间太短了
#13 的wwwwb说得应该是对的
java好像有个System.nanotime()的函数,不知道能不能精确的纳秒.不过System.currentTimeMillis()还是可以检测到毫秒
SHOW PROFILES
mysql> SELECT @@profiling;
+-------------+
| @@profiling |
+-------------+
| 0 |
+-------------+
1 row in set (0.00 sec)mysql> SET profiling = 1;
Query OK, 0 rows affected (0.00 sec)mysql> DROP TABLE IF EXISTS t1;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> CREATE TABLE T1 (id INT);
Query OK, 0 rows affected (0.01 sec)mysql> SHOW PROFILES;
+----------+----------+--------------------------+
| Query_ID | Duration | Query |
+----------+----------+--------------------------+
| 0 | 0.000088 | SET PROFILING = 1 |
| 1 | 0.000136 | DROP TABLE IF EXISTS t1 |
| 2 | 0.011947 | CREATE TABLE t1 (id INT) |
+----------+----------+--------------------------+
3 rows in set (0.00 sec)mysql> SHOW PROFILE;
+----------------------+----------+
| Status | Duration |
+----------------------+----------+
| checking permissions | 0.000040 |
| creating table | 0.000056 |
| After create | 0.011363 |
| query end | 0.000375 |
| freeing items | 0.000089 |
| logging slow query | 0.000019 |
| cleaning up | 0.000005 |
+----------------------+----------+
7 rows in set (0.00 sec)mysql> SHOW PROFILE FOR QUERY 1;
+--------------------+----------+
| Status | Duration |
+--------------------+----------+
| query end | 0.000107 |
| freeing items | 0.000008 |
| logging slow query | 0.000015 |
| cleaning up | 0.000006 |
+--------------------+----------+
4 rows in set (0.00 sec)mysql> SHOW PROFILE CPU FOR QUERY 2;
+----------------------+----------+----------+------------+
| Status | Duration | CPU_user | CPU_system |
+----------------------+----------+----------+------------+
| checking permissions | 0.000040 | 0.000038 | 0.000002 |
| creating table | 0.000056 | 0.000028 | 0.000028 |
| After create | 0.011363 | 0.000217 | 0.001571 |
| query end | 0.000375 | 0.000013 | 0.000028 |
| freeing items | 0.000089 | 0.000010 | 0.000014 |
| logging slow query | 0.000019 | 0.000009 | 0.000010 |
| cleaning up | 0.000005 | 0.000003 | 0.000002 |
+----------------------+----------+----------+------------+