Monday, August 25, 2014

Connect TO MSSQL Server 2012 using PERL Script

# Connect to remote machine using IP Address

my $host     = 'xxx.xxx.xx.xxx';
my $database = 'database_name';
my $user     = 'username';
my $pass    = 'password';

# Connect to remote machine using Server Name

my $host     = 'ServerName';
my $database = 'database_name';
my $user     = 'username';
my $pass    = 'password';


my $dsn = "dbi:ODBC:Driver={SQL Server};Server=$host;Database=$database";
my $dbh = DBI->connect($dsn, $user, $auth, { RaiseError => 1 });


Wednesday, August 13, 2014

Privileges error while accessing DB through PERL script

Error occurred though PERL script while accessing MySQL database.

Error : 
DBI connect('database=DB_NAME','root',...) failed: Access denied for user 'root'@'localhost' (using password: NO) at a.pl line 16

Solution : 
grant all privileges on DB_NAME.* to 'root'@'localhost' identified by '';

How to find version of PERL mudules


PERL Script Name : find_module_version.pl

#!/usr/bin/perl

use CPAN;

printf("%-20s %10s %10s\n", "Module", "Installed", "CPAN");

foreach $a (@ARGV) {
  foreach $mod (CPAN::Shell->expand("Module", $a)){
    printf("%-20s %10s %10s %s\n",
      $mod->id,
      $mod->inst_version eq "undef" || !defined($mod->inst_version)
        ? "-" : $mod->inst_version,
      $mod->cpan_version eq "undef" || !defined($mod->cpan_version)
        ? "-" : $mod->cpan_version,
      $mod->uptodate ? "" : "*"
    );
  }
}


perl find_module_version.pl MODULE_NAME


Monday, August 11, 2014

How to calculate the DB Size of MYSQL

SELECT table_schema "Database Name"
     , SUM(data_length + index_length) / (1024 * 1024) "Database Size in MB"
FROM information_schema.TABLES
GROUP BY table_schema