Skip to content

Commit 5361a79

Browse files
committed
Fix script for MySQL 8.x +
1 parent 7052322 commit 5361a79

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

mysql_zbx_part.pl

100644100755
Lines changed: 22 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,30 @@
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';
7980

81+
# MySQL 5.6 + MariaDB
82+
# my $sth = $dbh->prepare(qq{SELECT plugin_status FROM information_schema.plugins WHERE plugin_name = 'partition'});
83+
#
84+
# $sth->execute();
85+
#
86+
# my $row = $sth->fetchrow_array();
87+
#
88+
# $sth->finish();
89+
# return 1 if $row eq 'ACTIVE';
90+
91+
#MySQL 8.x (NOT MariaDB!)
92+
my $sth = $dbh->prepare(qq{select version();});
8093
$sth->execute();
81-
8294
my $row = $sth->fetchrow_array();
83-
95+
8496
$sth->finish();
97+
return 1 if $row >= 8;
8598

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

92102
sub create_next_partition {
@@ -97,7 +107,6 @@ sub create_next_partition {
97107
for (my $curr_part = 0; $curr_part < $amount_partitions; $curr_part++) {
98108
my $next_name = name_next_part($tables->{$table_name}->{'period'}, $curr_part);
99109
my $found = 0;
100-
101110
foreach my $partition (sort keys %{$table_part}) {
102111
if ($next_name eq $partition) {
103112
syslog(LOG_INFO, "Next partition for $table_name table has already been created. It is $next_name");

0 commit comments

Comments
 (0)