Get the App
SLTechnology News&Howtos  ›  Database  › 

How to add Partition automatically by mysql

Shulou Source: shulou.com Published: 2022-05-31 18:02:32 11月15日 Update

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!

Tags: Content commands more knowledge email practical maximum success learning next name dilemma reality situation article date case editor website industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology vpn Apple Microsoft