您现在的位置是:网站首页> 编程资料编程资料
实现MySQL定时批量检查表repair和优化表optimize table的shell脚本_linux shell_
2023-05-26
380人已围观
简介 实现MySQL定时批量检查表repair和优化表optimize table的shell脚本_linux shell_
本文介绍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您可能感兴趣的文章:
相关内容
- Linux下实现SNMP一键安装的Shell脚本_linux shell_
- linux下采用shell脚本实现批量为指定文件夹下图片添加水印的方法_linux shell_
- Shell脚本实现的memcached进程监控_linux shell_
- 智能监测自动重启Apache服务器的Shell脚本_linux shell_
- 阿里云主机一键安装lamp、lnmp环境的shell脚本分享_linux shell_
- Shell多线程操作及线程数控制实例_linux shell_
- Shell获取文件的文件名和扩展名的例子_linux shell_
- 使用bash shell删除目录中的特定文件的3种方法_linux shell_
- 5个实用的shell脚本面试题和答案_linux shell_
- Shell脚本编程中常用的数学运算实例_linux shell_
