mysqlexecdelete_sql

#!/bin/bash
#auther:don 2022/09/30
#version 01
mysql_bin="mysql6603"
mysql_user="root"
mysql_password="xxxxxx"
mysql_sock_path="/home/mysql_6603/mysql.sock"
#sql_query=$4
mysql_host=localhost
mysql_port=6603
dbname="feifeicms"
DATE=$(date +'%Y%m%d%H%M%S')
LogFile=/tmp/${DATE}mysql_exec.log
sql_dir="/home/qqc/sql"

function font
{
while (($#!=0))
do
case $1 in
-b ) echo -ne " ";;
-t ) echo -ne " ";;
-n ) echo -ne "\n";;
-black ) echo -ne "\033[30m";;
-red ) echo -ne "\033[31m";;
-green ) echo -ne "\033[32m";;
-yellow ) echo -ne "\033[33m";;
-blue ) echo -ne "\033[34m";;
-purple ) echo -ne "\033[35m";;
-cyan ) echo -ne "\033[36m";;
-gray ) echo -ne "\033[37m";;
-reset ) echo -ne "\033[0m";;
-h|-help|--help ) echo "Usage: font -color1 message1 -color2 message2 ...";
echo "eg: font -red [ -blue message1 message2 -red ]";;
* ) echo -ne "$1";;
esac
shift
done
}

function exec_mysql(){
if [[ ! -z "${mysql_sock_path}" && ! -z "${mysql_port}" && ! -z "${mysql_bin}" ]];then
font -purple "command is have 开始执行...."
else
font -purple "command is no have and exit..."
exit
fi
test ! -d ${sql_dir} && mkdir -p ${sql_dir}
font -purple "start exec_sql,$(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
#for i in `ls /home/qqc/sql/* |awk '{print $NF}'`
#for i in `ls /home/qqc/sql/* | xargs -n1`
cd ${sql_dir}
for i in `ls *.sql`
do
#${mysql_bin} -P ${mysql_port} -S ${mysql_sock_path} -u${mysql_user} -p${mysql_password} -h${mysql_host} -e "use feifeicms; tee /tmp/exec.log;source $i;" 2>/dev/null |grep -v _schema|sed '1d' >> $LogFile
${mysql_bin} -P ${mysql_port} -S ${mysql_sock_path} -u${mysql_user} -p${mysql_password} -h${mysql_host} ${dbname} < $i >>$LogFile
done
if [ $? -eq 0 ];then
echo "sql处理完成"
fi
font -purple "exec_sql_end,$(date +"%Y-%m-%d %H:%M:%S")" >> $LogFile
}
function watch_processlis_log() {
if [ -e "$log" ];then
touch $log

fi
#每5秒统计一下mysql_进程的delete语句
watch -n 5 '${mysql_bin} -P ${mysql_port} -S ${mysql_sock_path} -u${mysql_user} -p${mysql_password} -h${mysql_host} -e "show processlist" |egrep -i "DELETE" | tee -a txt.log'
}

#fifofile=/tmp/$$
#mkfifo $fifofile
#exec 1000<>$fifofile
#for i in `seq 1 10`
#do
#read -u1000
# {
# exec_mysql
# echo $i
#sleep 1
#echo >&1000
#}&
#done
#wait
#exec 1000>&
#rm -f $fifofile
tag=0
function main() {
while true
do
if [ "$tag" -eq $? ];then
exec_mysql
watch_processlis_log

fi
break

done
}
main

 
posted @ 2022-11-23 09:11  人生信条~~  阅读(54)  评论(0编辑  收藏  举报