一个linux下mysql批量查询的shell脚本:
[size=medium][color=indigo][i]#!/bin/sh
mysql -u****** -p****** dbname --default-character-set=gb2312 -vvv << eof
show create table log;
show index from log;
explain partitions select count(*) from log where date = 20090505 and time >= 000500 and time <= 002205;
explain partitions select distinct(domain) from log where date = 20090505 and time >= 000500 and time <= 002205 and sip = 3232235534;
select count(*) from log where date = 20090505 and time >= 000500 and time <= 002205;
select distinct(domain) from log where date = 20090505 and time >= 000500 and time <= 002205 and sip = 3232235534;
exit
eof
exit[/i][/color][/size]
1) 为了回显以输出被执行的命令(格式化结果及每条命令执行的时间,同交互式使用mysql),使用mysql -vvv。
2) 可通过nohup命令后台运行该脚本并将脚本输出重定向指定文件。
[color=indigo][size=medium][u][i]# nohup ./dbtesting.sh > dbtesting.log &[/i][/u][/size][/color]
3) 实时查看输出文件
[color=indigo][size=medium][u][i]# tail -f dbtesting.log[/i][/u][/size][/color]
[url=http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html#batch-mode]参考:MySQL 5.1参考手册 3.5. 在批处理模式下使用mysql[/url]
[size=medium][color=indigo][i]#!/bin/sh
mysql -u****** -p****** dbname --default-character-set=gb2312 -vvv << eof
show create table log;
show index from log;
explain partitions select count(*) from log where date = 20090505 and time >= 000500 and time <= 002205;
explain partitions select distinct(domain) from log where date = 20090505 and time >= 000500 and time <= 002205 and sip = 3232235534;
select count(*) from log where date = 20090505 and time >= 000500 and time <= 002205;
select distinct(domain) from log where date = 20090505 and time >= 000500 and time <= 002205 and sip = 3232235534;
exit
eof
exit[/i][/color][/size]
1) 为了回显以输出被执行的命令(格式化结果及每条命令执行的时间,同交互式使用mysql),使用mysql -vvv。
2) 可通过nohup命令后台运行该脚本并将脚本输出重定向指定文件。
[color=indigo][size=medium][u][i]# nohup ./dbtesting.sh > dbtesting.log &[/i][/u][/size][/color]
3) 实时查看输出文件
[color=indigo][size=medium][u][i]# tail -f dbtesting.log[/i][/u][/size][/color]
[url=http://dev.mysql.com/doc/refman/5.1/zh/tutorial.html#batch-mode]参考:MySQL 5.1参考手册 3.5. 在批处理模式下使用mysql[/url]