Skip to content

Commit 5e174c1

Browse files
authored
Merge pull request #2 from OpensourceICTSolutions/add_mysql_8_support
Fix script for MySQL 8.x +
2 parents 7052322 + b06ec8f commit 5e174c1

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ On a Debian based systems run:
5757
apt-get install libdatetime-perl liblogger-syslog-perl
5858
```
5959

60+
MAKE SURE TO UNCOMMENT THE CORRECT LINES FOR THE VERSION YOU NEED. Check the blog post for more information.
61+
```
62+
# MySQL 5.5
63+
# MySQL 5.6 + MariaDB
64+
# MySQL 8.x (NOT MariaDB!)
65+
```
6066

6167
That's it! You are now done and you have setup MySQL partitioing. We could execute the script manually with:
6268
```

mysql_zbx_part.pl

100644100755
Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@
4343
exit 1;
4444
}
4545

46-
my $sth = $dbh->prepare(qq{SELECT table_name, partition_name, lower(partition_method) as partition_method,
47-
rtrim(ltrim(partition_expression)) as partition_expression,
48-
partition_description, table_rows
46+
my $sth = $dbh->prepare(qq{SELECT table_name as table_name, partition_name as partition_name,
47+
lower(partition_method) as partition_method,
48+
rtrim(ltrim(partition_expression)) as partition_expression,
49+
partition_description as partition_description, table_rows
4950
FROM information_schema.partitions
5051
WHERE partition_name IS NOT NULL AND table_schema = ?});
5152
$sth->execute($db_schema);
@@ -72,21 +73,36 @@
7273

7374
sub check_have_partition {
7475
my $result = 0;
76+
7577
# MySQL 5.5
76-
#my $sth = $dbh->prepare(qq{SELECT variable_value FROM information_schema.global_variables WHERE variable_name = 'have_partitioning'});
77-
# MySQL 5.6 + MariaDB
78-
my $sth = $dbh->prepare(qq{SELECT plugin_status FROM information_schema.plugins WHERE plugin_name = 'partition'});
78+
# #my $sth = $dbh->prepare(qq{SELECT variable_value FROM information_schema.global_variables WHERE variable_name = 'have_partitioning'});
79+
#return 1 if $row eq 'YES';
80+
#
81+
# End of Mysql 5.5
7982

83+
# MySQL 5.6 + MariaDB
84+
# my $sth = $dbh->prepare(qq{SELECT plugin_status FROM information_schema.plugins WHERE plugin_name = 'partition'});
85+
#
86+
# $sth->execute();
87+
#
88+
# my $row = $sth->fetchrow_array();
89+
#
90+
# $sth->finish();
91+
# return 1 if $row eq 'ACTIVE';
92+
#
93+
# End of MySQL 5.6 + MariaDB
94+
95+
# MySQL 8.x (NOT MariaDB!)
96+
my $sth = $dbh->prepare(qq{select version();});
8097
$sth->execute();
81-
8298
my $row = $sth->fetchrow_array();
83-
99+
84100
$sth->finish();
101+
return 1 if $row >= 8;
102+
#
103+
# End of MySQL 8.x
85104

86-
# MySQL 5.5
87-
#return 1 if $row eq 'YES';
88-
# MySQL 5.6 + MariaDB
89-
return 1 if $row eq 'ACTIVE';
105+
# Do not uncomment last }
90106
}
91107

92108
sub create_next_partition {
@@ -97,7 +113,6 @@ sub create_next_partition {
97113
for (my $curr_part = 0; $curr_part < $amount_partitions; $curr_part++) {
98114
my $next_name = name_next_part($tables->{$table_name}->{'period'}, $curr_part);
99115
my $found = 0;
100-
101116
foreach my $partition (sort keys %{$table_part}) {
102117
if ($next_name eq $partition) {
103118
syslog(LOG_INFO, "Next partition for $table_name table has already been created. It is $next_name");

0 commit comments

Comments
 (0)