ITeye博客

Linux下批处理模式使用Mysql

jef · 2009-05-13 16:11 · 笔记 · Markdown

一个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

参考:MySQL 5.1参考手册 3.5. 在批处理模式下使用mysql

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。