1
2
3
4
5
6
7
8
9
10
11
|
[mysqld]
#开启慢查询
log_slow_queries = ON
#指定日志文件存放位置,可以为空,系统会给一个缺省的文件host_name-slow.log
log-slow-queries =
/usr/local/mysq/var/slowquery
.log
#记录超过的时间,默认为10s
long_query_time = 1
#log下来没有使用索引的query,可以根据情况决定是否开启
log-queries-not-using-indexes
#执行速度较慢的管理命令(比如OPTIMEZE TABLE)也会被记录
log-slow-admin-statements
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#生成随机字符串函数,在存储过程中调用
delimiter $$
create
function
rand_string(n
int
)
returns
varchar
(255)
begin
declare
chars_str
varchar
(100)
default
'abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
declare
return_str
varchar
(255)
default
''
;
declare
i
int
default
0;
while i<n do
set
return_str = concat(return_str,
substring
(chars_str,floor(1+rand()*52),1));
set
i = i + 1;
end
while;
return
return_str;
end
$$
delimiter ;
#生成随机数字,在存储过程中调用
delimiter $$
create
function
rand_num()
returns
int
(5)
begin
declare
i
int
default
0;
set
i = floor(10+rand()*500);
return
i;
end
$$
delimiter ;
#定义存储过程
delimiter $$
create
procedure
insert_emp(start
int
(10),max_num
int
(10))
begin
declare
i
int
default
0;
set
autocommit = 0;
repeat
set
i = i+1;
insert
into
emp
values
((start+i),rand_string(6),
'SALESMAN'
,0001,2000,400,rand_num(),curdate());
until i = max_num
end
repeat;
end
$$
|
1
2
3
4
5
|
# Time: 131010 16:31:11
# User@Host: root[root] @ localhost []
# Query_time: 1.045439 Lock_time: 0.000057 Rows_sent: 1 Rows_examined: 5000000
SET timestamp=1381393871;
select
* from emp where
id
=1000000;
|