求一个linux下的shell脚本执行mysql的sql语句,但老是 不成功....大神帮忙啊...
想通过shell根据查询条件删除部分数据...请大指定下...前面查询没问题..可就是进行for循环时没执行...执行脚本的时候又没报错...真心搞不懂了...脚本如下:...
想通过shell根据查询条件删除部分数据...请大指定下...前面查询没问题..可就是进行for循环时没执行...执行脚本的时候又没报错...真心搞不懂了...
脚本如下:
sqlx="/opt/mysql3307/bin/mysql test -e 'delete from test.text where id >3;'"
sqlw="select id from test.text where id>3;"
sqltool="/opt/mysql3307/bin/mysql test"
echo "$sqlw" | $sqltool >testsss.log
a= awk 'NR==2{print $1}' testsss.log
#echo $a
#echo $sqlw
for num in $a
do
if [ "$num" -gt "3" ]
then
#echo "$sqlx" | $sqltool > test232.log
#$sqltool -e 'update test.text set times = now();'
/opt/mysql3307/bin/mysql test <<EOF
delete from test.text where id >3;
commit;
EOF
fi
done 展开
脚本如下:
sqlx="/opt/mysql3307/bin/mysql test -e 'delete from test.text where id >3;'"
sqlw="select id from test.text where id>3;"
sqltool="/opt/mysql3307/bin/mysql test"
echo "$sqlw" | $sqltool >testsss.log
a= awk 'NR==2{print $1}' testsss.log
#echo $a
#echo $sqlw
for num in $a
do
if [ "$num" -gt "3" ]
then
#echo "$sqlx" | $sqltool > test232.log
#$sqltool -e 'update test.text set times = now();'
/opt/mysql3307/bin/mysql test <<EOF
delete from test.text where id >3;
commit;
EOF
fi
done 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询