专注于 JetBrains IDEA 全家桶,永久激活,教程
持续更新 PyCharm,IDEA,WebStorm,PhpStorm,DataGrip,RubyMine,CLion,AppCode 永久激活教程

mysql批量进行optimize table操作

数据库运行一段时间后,有可能会有磁盘磁片产生,此时我们需要进行optimize table操作

# 获取需要optimize的表:如下为获取总大小小于80G的表进行操作:
mysql -utroot -S /tmp/mysql_3306.sock -sNe “select concat(table_schema,’.’,table_name), table_schema,table_name,ENGINE, sum(data_length/1024/1024) as data_mb , sum(index_length/1024/1024) as index_mb, sum((data_length+index_length)/1024/1024) as all_mb, sum(table_rows) from information_schema.tables where table_schema not in(‘mysql’,’performance_schema’,’information_schema’) and engine in (‘innodb’,’myisam’) group by table_schema,table_name having all_mb<=80000 order by all_mb asc ;”

将上面获取到的表名写入一个文件,如optimiz_table.tables
写个脚本来循环跑
#!/bin/bash
set -eux
set -o pipefail

table_file=’optimize_table.tables’
log_file=’optimize_table.log’

while read line
do
sql=”optimize table $line”
echo “`date +”%F %T”`: begin $sql” | tee -a “$log_file”
mysql -uroot -S /tmp/mysql_3306.sock -e “$sql” 2>&1 | tee -a “$log_file”
echo “`date +”%F %T”`: sucess $sql” | tee -a “$log_file”
sleep 1
done < “$table_file”

未经允许不得转载:搜云库技术团队 » mysql批量进行optimize table操作

JetBrains 全家桶,激活、破解、教程

提供 JetBrains 全家桶激活码、注册码、破解补丁下载及详细激活教程,支持 IntelliJ IDEA、PyCharm、WebStorm 等工具的永久激活。无论是破解教程,还是最新激活码,均可免费获得,帮助开发者解决常见激活问题,确保轻松破解并快速使用 JetBrains 软件。获取免费的破解补丁和激活码,快速解决激活难题,全面覆盖 2024/2025 版本!

联系我们联系我们