Zabbix MySQL Tuning

Source: Internet
Author: User

Select table_name as "Tables", Round (((data_length + index_length)/1024/1024), 2) ' Size in MB ' from Information_schema . TABLES WHERE table_schema = ' Zabbix ' ORDER by (data_length + index_length) DESC limit 10; (View MySQL database table size)


First, the Conversion partition table

Alter table history partition by range ( clock)   (partition p20160301  VALUES LESS THAN  (Unix_timestamp (' 2016-03-01 ')); Alter table history_log partition by range ( clock)   (PARTITION  p20160301 values less than  (Unix_timestamp (' 2016-03-01 ')); Alter table history_str partition by range ( clock)   (PARTITION  p20160301 values less than  (Unix_timestamp (' 2016-03-01 ')); Alter table history_text partition by range ( clock)   (PARTITION  p20160301 values less than  (Unix_timestamp (' 2016-03-01 ')); Alter table history_uint partition by range ( clock)   (PARTITION  p20160301 values less than  (Unix_timestamp (' 2016-03-01 ')); Alter table trends partition by range ( clock)   (partition p20160301 values less than  (Unix_timestamp (' 2016-03-01 ')); Alter table trends_uint partition by range ( clock)   (PARTITION  p20160301 values less than  (Unix_timestamp (' 2016-03-01 '));


Second, execute the script

delimiter //drop procedure if exists  ' Zabbix '. ' Create_zabbix_partitions '  // create procedure  ' Zabbix '. ' Create_zabbix_partitions '   () begincall zabbix.create_next_ Partitions ("Zabbix", "history"); Call zabbix.create_next_partitions ("Zabbix", "History_log"); Call zabbix.create_next_partitions ("Zabbix", "history_str"); Call zabbix.create_next_partitions ("Zabbix", "History_text"); Call zabbix.create_next_partitions ("Zabbix", "History_uint"); Call zabbix.create_next_partitions ("Zabbix", "Trends"); Call zabbix.create_next_partitions ("Zabbix", "Trends_uint"); Call zabbix.drop_old_partitions ("Zabbix", "history"); Call zabbix.drop_old_partitions ("Zabbix", "History_log"); Call zabbix.drop_old_partitions ("Zabbix", "history_str"); Call zabbix.drop_old_partitions ("Zabbix", "History_text"); Call zabbix.drop_old_partitions ("Zabbix", "History_uint"); Call zabbix.drop_old_partitions ("Zabbix", "Trends"); Call zabbix.droP_old_partitions ("Zabbix", "Trends_uint"); end //drop procedure if exists  ' Zabbix '. ' Create_next_partitions '  //CREATE  procedure  ' Zabbix '. ' Create_next_partitions '   (Schemaname varchar (+), tablename  varchar) Begindeclare nextclock timestamp;declare partitionname varchar (+);D Eclare  CLOCK int; set  @totaldays  = 7; Set @i = 1;createloop: loopset nextclock = date_add (now (), INTERVAL @i  day); Set partitionname = date_format ( NEXTCLOCK,  ' p%y%m%d '  ); Set clock = unix_timestamp (Date_format (Date_add ( nextclock ,interval 1 day) , '%y-%m-%d 00:00:00 ')); Call zabbix.create_partition ( SCHEMANAME, TABLENAME, PARTITIONNAME, CLOCK ); set @[email protected]+1;if @i >  @totaldays  THENLEAVE createloop; end if; end loop; End //drop procedure if exists  ' Zabbix '. ' Drop_old_partitions '  //create procedure   ' Zabbix '. ' Drop_old_partitions '   (Schemaname varchar),  tablename varchar (64)) Begindeclare oldclock timestamp;declare partitionname varchar (;D) eclare clock  int set  @mindays  = 30; set  @maxdays  =  @mindays +4; set @i =  @maxdays;d Roploop: loopset oldclock = date_sub (now (), INTERVAL  @i day); Set partitionname = date_format ( OLDCLOCK,  ' p%y%m%d '  ); Call zabbix.drop_partition ( SCHEMANAME, TABLENAME, PARTITIONNAME ); set @[email protected];if @i <=  @mindays  THENLEAVE droploop; end if; end loop; end //drop procedure if exists  ' Zabbix '. ' Create_partition '  //CREATE  procedure  ' Zabbix '. ' Create_partition '   (Schemaname varchaR (UP),  tablename varchar ( partitionname varchar),  clock int) BEGINDECLARE  RETROWS int; Select count (1)  INTO RETROWSFROM  ' information_schema '. ' Partitions ' where  ' Table_schema '  = SCHEMANAME AND  ' table_name '  = TABLENAME AND  ' partition_name '   = partitionname;                                        if retrows = 0 thenselect concat (  "Create_ Partition (", schemaname, ", ", tablename, ", ", partitionname, ", ",  clock,   ")"  )  AS msg; set  @sql  = concat (  ' alter table  ', schemaname,  '.,  tablename,   ', '  ADD PARTITION  (partition  ',  partitionname,  '  VALUES LESS THAN  (', clock,  ')); '  ); prepare stmt from  @sql; execute stmt;deallocate prepare stmt; end if; end //drop procedure if exists  ' Zabbix '. ' Drop_partition '  //create procedure   ' Zabbix '. ' Drop_partition '   (Schemaname varchar),  tablename varchar (+),  Partitionname varchar (+)) begindeclare retrows int; Select count (1)  INTO RETROWSFROM  ' information_schema '. ' Partitions ' where  ' Table_schema '  = SCHEMANAME AND  ' table_name '  = TABLENAME AND  ' partition_name '   = partitionname;                                        if retrows = 1 thenselect concat (  "DRop_partition (", schemaname, ", ", tablename, ", ", partitionname, ") " "  AS msg; set  @sql  = concat (  ' alter table  ', schemaname,  '.,  tablename,   ', '  DROP PARTITION  ', partitionname,  '; '  ); prepare stmt from  @sql; execute stmt;deallocate prepare stmt; end if; end //delimiter ;

Save the above code in the Partition.sql file

Perform

/apps/mysql/bin/mysql-uroot [email protected] Zabbix </apps/mysql/partition.sql/apps/mysql/bin/mysql-b Zabbix- uroot [email protected]-E "call Create_zabbix_partitions ();"

Third, join Crontab

* * * */apps/mysql/bin/mysql-uroot [email protected] Zabbix </apps/mysql/partition.sql59 * * */APPS/MYSQL/BI N/mysql-b zabbix-uroot [email protected]-E "call Create_zabbix_partitions ();"


Zabbix MySQL Tuning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.