本文介绍Mysql定时批量检查表repair和优化表optimize table的shell脚本,对于mysql数据库的定期维护相当有用!如下所示: #!/bin/bash host_name=192.
本文介绍Mysql定时批量检查表repair和优化表optimize table的shell脚本,对于mysql数据库的定期维护相当有用!如下所示:
#!/bin/bash
host_name=192.168.0.123
user_name=jincon.com
user_pwd=jincon.com
database=my_db_name
need_optmize_table=true
tables=$(mysql -h$host_name -u$user_name -p$user_pwd $database -A -Bse "show tables")
for table_name in $tables
do
check_result=$(mysql -h$host_name -u$user_name -p$user_pwd $database -A -Bse
"check table $table_name" | awk '{ print $4 }')
if [ "$check_result" = "OK" ]
then
echo "It's no need to repair table $table_name"
else
echo $(mysql -h$host_name -u$user_name -p$user_pwd $database -A -Bse
"repair table $table_name")
fi
# 优化表,可提高性能
if [ $need_optmize_table = true ]
then
echo $(mysql -h$host_name -u$user_name -p$user_pwd $database -A -Bse
"optimize table $table_name")
fi
done
--结束END--
本文标题: 实现MySQL定时批量检查表repair和优化表optimize table的shell脚本
本文链接: https://lsjlt.com/news/17760.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0