Connect with Perl

SingleStore supports the basic Perl drivers for MySQL using the standard DBI and DBM drivers. You may install and configure Perl using any of the supported methods, but you must have the MySQL driver to get Perl to work with SingleStore. You can also use the MariaDB Perl library.

SingleStore supports Kerberos authentication. See Authenticate using Kerberos for more information.

Install Drivers for Perl

The following example installs the Perl drivers with the basic CPAN method:

$ perl -MCPAN -e shell
cpan> install DBI
cpan> install DBD::mysql

This command installed the following version of DBI and DBD:

perl -MDBI -e 'print $DBI::VERSION."\n"' # 1.642
perl -MDBD::mysql -e 'print $DBD::mysql::VERSION."\n"' # 4.050

Here's a sample script to test connectivity using the installed drivers. The following script connects to a cluster and retrieves some basic information about the cluster.

#!/usr/bin/perl
use strict;
use DBI;
my $host = "<ip_address_or_hostname";
my $database = "information_schema"; my $port = 3306;
my $tablename = "mv_activities";
my $user = "root";
my $pw = "";
my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host",$user, $pw) or die "Cannot connect to MySQL server\n";
my $sql = 'select @@memsql_version';
my $sth = $dbh->prepare($sql);
$sth->execute();
while (my @row = $sth->fetchrow_array) {
print "MemSQL_Version: $row[0] \n";
}
my $sql = 'select count(*) from aggregators';
my $sth = $dbh->prepare($sql);
$sth->execute();
while (my @row = $sth->fetchrow_array) {
print "Aggregators: $row[0] \n";
}
my $sql = 'select count(*) from leaves';
my $sth = $dbh->prepare($sql);
$sth->execute();
while (my @row = $sth->fetchrow_array) {
print "Leaves $row[0] \n";
}
my $sql = 'select variable_name, variable_value from information_schema.global_status where variable_name = "uptime"';
my $sth = $dbh->prepare($sql);
$sth->execute();
while (my @row = $sth->fetchrow_array) {
#print "variable_name $row[0] variable_value $row[1]\n";
print "Cluster has been up for $row[1] seconds! \n";
}

Replace ip_address_or_hostname in the code above with the IP address or the hostname of your cluster. Here's a sample output:

$ ./show_cluster.pm
MemSQL_Version: 6.7.14 Aggregators: 1
Leaves 2
Cluster has been up for 16025 seconds!

Authenticate using Kerberos

The following example shows how to use Kerberos authentication with the script above. Since, the script is compiled locally with CPAN, it works out of the box. Remember to comment out the password line.

#my $pw = "";
#my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host",$user, $pw) or die "Cannot connect to MySQL server\n";
my $dbh = DBI->connect("DBI:mysql:database=$database;host=$host",$user ) or die "Cannot connect to MySQL server\n";

Here's a sample output:

[ec2-user perl]$ klist
Ticket cache: KEYRING:persistent:1000:1000
Default principal: tron@LOCALHOST
Valid starting Expires Service principal
04/15/2019 23:47:37 04/16/2019 23:31:56 memsql/memsql.localhost@LOCALHOST
04/15/2019 23:31:56 04/16/2019 23:31:56 krbtgt/LOCALHOST@LOCALHOST
[ec2-user perl]$ ./show_cluster.pm
MemSQL_Version: 6.7.15
Aggregators: 1
Leaves 1
Cluster has been up for 1306 seconds!

DBD-MariaDB Perl Library

SingleStore also supports the MariaDB Perl Library v1.11 (GPLv2).

Binary

URL

Platform independent, includes source code

DBD-MariaDB-1.11.tar.gz

Last modified: April 7, 2023

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK