mysql簡單的碎片清理指令碼

轉身淚傾城發表於2016-05-13
mysql簡單的碎片清理指令碼 
#!/bin/bash 
date=`date +”%Y-%m-%d %H:%M:%S”` 
echo $date >>/root/qingli.log 
tables=$(/usr/local/mysql/bin/mysql -u root -p”tina” 2>/dev/null -e “select concat(table_schema,`.`,table_name) from information_schema.tables where data_free>0 and engine !=`MEMORY`;” |grep -v “concat” |grep -v “tinatest” |grep -v “information_schema” |grep -v “mysql”) 

for table in $tables 
do 
  /usr/local/mysql/bin/mysql -u root-p”tina” 2>/dev/null -e “optimize no_write_to_binlog table $table;” >>/root/qingli.log 
done 

新增no_write_to_binlog,是為了保證只在這個主庫上執行,這個命令不用傳到從庫,以免從庫執行過久,導致同步延遲

相關文章