In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MySQL DBA occasionally encounters because there is not enough space, and before you cannot delete data, you may think of temporarily solving the space problem by deleting binlog. I also encountered this situation on the weekend, because I was not next to the computer, find the leader and use my mobile phone to type the command to the boss to delete the binlog. Think about writing a binlog deletion tool. If you encounter such problems in the future, it is appropriate to use the scripting tool directly.
Delbinlog.sh
#! / bin/bash
# # author yangyi@youzan.com
# date 20160327
# delnums is how many are deleted at a time, and deleted in batches.
# rest_num is the number of binlog to be retained, which can be adjusted according to the actual situation.
If [$#-lt 4]; then
Echo "Usage: $0-p PORT-r res_nums"
Exit 1
Fi
While getopts ": PRV r:" arg
Do
Case $arg in
p)
# echo "packs arg:$OPTARG"
PORT=$OPTARG
r)
# echo "dudes arg:$OPTARG"
Res_nums=$OPTARG
?) # what is arg when there is an unrecognized option?
Echo "unkonw argument"
Echo "Usage: $0-p PORT-r res_nums"
Exit 1
Esac
Done
If [- S / srv/my_$PORT/mysqld.sock]; then
SOCKET= "/ srv/my_$PORT/mysqld.sock"
Elif [- S / srv/my$PORT/run/mysql.sock]; then
SOCKET= "/ srv/my$PORT/run/mysql.sock"
Fi
MYSQL= "mysql-uroot-S ${SOCKET}"
Del_nums=3
Logs_num= `$ MYSQL-e "show master logs;" | wc-l `
Echo "there are $logs_num binary logs."
If [[$res_nums-gt $logs_num]]
Then
Exit 0
Fi
While [[$res_nums-lt $logs_num]; do
Del_to_binlog= `$ MYSQL-- skip-column-names-e "show master logs;" | head-n $del_nums | awk 'END {print $1}' `
$MYSQL-e "purge master logs to'$del_to_binlog';"
Echo "purge master logs to $del_to_binlog..."
Logs_num= `$ MYSQL-- skip-column-names-e "show master logs;" | wc-l `
Sleep 2
Done
Logs_num= `$ MYSQL-e "show master logs;" | wc-l `
Echo "there are $logs_num binary logs."
If necessary, you can modify it appropriately according to the actual situation of your own production environment.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.