Commit 44359040 authored by Tuukka Pasanen's avatar Tuukka Pasanen Committed by Daniel Black

MDEV-28376: Make sure available Perl MariaDB DBI driver is chosen

Commit introduces automatic detection which supported
Perl MariaDB DBI driver is available:

 * DBD::mysql
 * DBD::MariaDB

If nothing is then bail out and die

Current Detection prefers Perl DBD:MariaDB driver.

This is mainly for older Linux distros or Windows which does not
have Perl DBD:MariaDB packaged or does not want to use Perl cpan command.
parent 99566fc8
......@@ -240,26 +240,56 @@ sub get_user_mycnf
sub connect_to_MySQL
{
print "connect_to_MySQL\n" if $op{debug};
my $dsn;
if($mycnf{'socket'} && -S $mycnf{'socket'})
{
$dsn = "DBI:MariaDB:mariadb_socket=$mycnf{socket}";
}
elsif($mycnf{'host'})
{
$dsn = "DBI:MariaDB:host=$mycnf{host}" . ($mycnf{port} ? ";port=$mycnf{port}" : "");
}
else
{
$dsn = "DBI:MariaDB:host=localhost";
}
print "connect_to_MySQL: DBI DSN: $dsn\n" if $op{debug};
$dbh = DBI->connect($dsn, $mycnf{'user'}, $mycnf{'pass'}) or die;
print "connect_to_MySQL\n" if $op{debug};
if(my @driverList = grep {/mariadb|mysql/i} DBI->available_drivers()) {
my $dsn;
my $driver = undef;
if(grep {/mariadb/i} @driverList)
{
$driver = "DBI:MariaDB";
}
elsif(grep {/mysql/i} @driverList)
{
$driver = "DBI:mysql";
}
if($mycnf{'socket'} && -S $mycnf{'socket'})
{
if(grep {/mariadb/i} @driverList)
{
$dsn = $driver . ":mariadb_socket=$mycnf{socket}";
}
elsif(grep {/mysql/i} @driverList)
{
$dsn = $driver . ":mysql_socket=$mycnf{socket}";
}
}
elsif($mycnf{'host'})
{
$dsn = $driver . ":host=$mycnf{host}" . ($mycnf{port} ? ";port=$mycnf{port}" : "");
}
else
{
$dsn = $driver . ":host=localhost";
}
print "connect_to_MySQL: DBI DSN: " . $dsn . "\n" if $op{debug};
$dbh = DBI->connect($dsn, $mycnf{'user'}, $mycnf{'pass'}) or die;
}
else
{
print STDERR "Install Perl 5.x driver: DBD:mysql or DBD:MariaDB\n";
print STDERR "currently installed Perl DBD drivers:\n";
foreach my $driver (DBI->available_drivers())
{
print STDERR " * " . $driver . "\n";
}
print STDERR "\n";
die("Exit as no MariaDB DBI driver found!\n");
}
}
sub collect_reports
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment