Linux下批处理模式使用Mysql

一个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]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值