Connect with Perl
On this page
SingleStore supports the basic Perl drivers for MySQL using the standard DBI and DBM drivers.
SingleStore supports Kerberos authentication.
Install Drivers for Perl
The following example installs the Perl drivers with the basic CPAN method:
$ perl -MCPAN -e shellcpan> install DBIcpan> install DBD::mysql
This command installed the following version of DBI and DBD:
perl -MDBI -e 'print $DBI::VERSION."\n"' # 1.642perl -MDBD::mysql -e 'print $DBD::mysql::VERSION."\n"' # 4.050
Here's a sample script to test connectivity using the installed drivers.
#!/usr/bin/perluse 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_
in the code above with the IP address or the hostname of your cluster.
$ ./show_cluster.pmMemSQL_Version: 6.7.14 Aggregators: 1Leaves 2Cluster has been up for 16025 seconds!
Authenticate using Kerberos
The following example shows how to use Kerberos authentication with the script above.
#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]$ klistTicket cache: KEYRING:persistent:1000:1000Default principal: tron@LOCALHOSTValid starting Expires Service principal04/15/2019 23:47:37 04/16/2019 23:31:56 memsql/memsql.localhost@LOCALHOST04/15/2019 23:31:56 04/16/2019 23:31:56 krbtgt/LOCALHOST@LOCALHOST[ec2-user perl]$ ./show_cluster.pmMemSQL_Version: 6.7.15Aggregators: 1Leaves 1Cluster has been up for 1306 seconds!
DBD-MariaDB Perl Library
SingleStore also supports the MariaDB Perl Library v1.
Binary |
URL |
---|---|
Platform independent, includes source code |
Last modified: April 7, 2023