Linux下批处理模式使用Mysql
一个linux下mysql批量查询的shell脚本:
*#!/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*
1) 为了回显以输出被执行的命令(格式化结果及每条命令执行的时间,同交互式使用mysql),使用mysql -vvv。 2) 可通过nohup命令后台运行该脚本并将脚本输出重定向指定文件。 # nohup ./dbtesting.sh > dbtesting.log & 3) 实时查看输出文件 # tail -f dbtesting.log