IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

mysql批量进行optimize table操作

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

数据库运行一段时间后,有可能会有磁盘磁片产生,此时我们需要进行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”


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(61) 打赏



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

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367