Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add Partition automatically by mysql

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces the relevant knowledge of "how to automatically increase partitions in mysql". In the operation of actual cases, many people will encounter such a dilemma. Next, let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

#! / bin/bashPATH= "/ usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin" LANG= "en_US.UTF-8" IFS= ":" add_partition () {dbserver= "$1" dbport= "$2" dbuser='root' dbpwd='test@123456' dbname= "$3" t_name=$4 # the name of the partition table Sqlcmd= "SELECT REPLACE (partition_name FROM INFORMATION_SCHEMA.PARTITIONS WHERE table_name='$t_name' and TABLE_SCHEMA ='$dbname' ORDER BY partition_ordinal_position DESC LIMIT 1 "# get the largest partition date: max_partition= `mysql-h$dbserver-u$dbuser-p$dbpwd-- port=$dbport-- database $dbname-e" $sqlcmd "| sed 1d `sqlcmd=" select date_add (date_format ('${max_partition} 01century sqlcmd=% Ymuri% mLY% d'), INTERVAL 2 month) Replace (left (date_add (date_format ('${max_partition} 01mMel% d'), INTERVAL 1 month), 7),'-' '') "awk midline = `mysql-h$dbserver-u$dbuser-p$dbpwd-- port=$dbport-- database $dbname-e" $sqlcmd "| sed 1d`proomtime= `echo $t_mid | awk'{print $1} '`proomname`echo $t_mid | awk' {print $2} '`sqlcmd=" ALTER TABLE $t_name ADD PARTITION (PARTITION p$ {p_name} VALUES LESS THAN (to_days (' $p_time}') "mysql-h$dbserver-u$dbuser-p$dbpwd-- port=$dbport-- database $dbname-e" $sqlcmd "if [$?-ne 0]; then mess=" dbserver:$dbserver;dbport:$dbport;dbname:$dbname; command: $sqlcmd execution failed "# email alarm partition increase failed exit 0 else mess=" dbserver:$dbserver;dbport:$dbport;dbname:$dbname Command: $sqlcmd successfully executed "fi;} serverlist= ('192.168.1.11 i=0let len_serverlist=$ 3306 i=0let len_serverlist=$ le $len_serverlist]. Do tasking list = (${serverlist [I]}) echo ${t_list [0]} ${t_list [1]} ${t_list [2]} ${t_list [3]} add_partition ${t_list [0]} ${t_list [1]} ${t_list [2]} ${t_list [3]} let i++done# mail alarm zone added normally " This is the end of the content of how to automatically add partitions to mysql. Thank you for your reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report