1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| #!/bin/bash
time=date -d yesterday +"%Y-%m-%d"
user="用户名"
host="主机ip"
passwd="用户密码"
#提前创建好一个存放目录:/opt/mysql/log/slowlog/
mv /opt/mysql/log/slow.log /opt/mysql/log/slowlog/slow-$time.log
gzip /opt/mysql/log/slowlog/slow-$time.log
mysqladmin -u$user -h$host -p$passwd --socket=/opt/mysql/run/mysql.sock flush-logs slow
|