diff --git a/bin/pt-archiver b/bin/pt-archiver index bd3a9a42..258a7be8 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -1709,51 +1709,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1762,12 +1721,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-config-diff b/bin/pt-config-diff index 0d83d401..08bc04f6 100755 --- a/bin/pt-config-diff +++ b/bin/pt-config-diff @@ -1262,51 +1262,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1315,12 +1274,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-deadlock-logger b/bin/pt-deadlock-logger index 7952fe41..08c3eae2 100755 --- a/bin/pt-deadlock-logger +++ b/bin/pt-deadlock-logger @@ -1525,51 +1525,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1578,12 +1537,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-duplicate-key-checker b/bin/pt-duplicate-key-checker index 4f3f1d0d..8518cf91 100755 --- a/bin/pt-duplicate-key-checker +++ b/bin/pt-duplicate-key-checker @@ -947,51 +947,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1000,12 +959,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-find b/bin/pt-find index f90379d9..ca23e859 100755 --- a/bin/pt-find +++ b/bin/pt-find @@ -237,51 +237,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -290,12 +249,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-fk-error-logger b/bin/pt-fk-error-logger index 7ab599e9..13e7bdcf 100755 --- a/bin/pt-fk-error-logger +++ b/bin/pt-fk-error-logger @@ -1381,51 +1381,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1434,12 +1393,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-heartbeat b/bin/pt-heartbeat index 7d3e1888..b273a380 100755 --- a/bin/pt-heartbeat +++ b/bin/pt-heartbeat @@ -1970,51 +1970,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -2023,12 +1982,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-index-usage b/bin/pt-index-usage index bfc5312a..779dc20c 100755 --- a/bin/pt-index-usage +++ b/bin/pt-index-usage @@ -237,51 +237,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -290,12 +249,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-kill b/bin/pt-kill index 1775592a..75756812 100755 --- a/bin/pt-kill +++ b/bin/pt-kill @@ -1406,51 +1406,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1459,12 +1418,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-log-player b/bin/pt-log-player index 6f7b9f5f..dd10183f 100755 --- a/bin/pt-log-player +++ b/bin/pt-log-player @@ -2217,51 +2217,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -2270,12 +2229,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index 9f821425..312e7b2f 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -1406,51 +1406,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1459,12 +1418,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-query-advisor b/bin/pt-query-advisor index 1936d291..ff9f3fbc 100755 --- a/bin/pt-query-advisor +++ b/bin/pt-query-advisor @@ -237,51 +237,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -290,12 +249,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 790cc28f..41611a1b 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -237,51 +237,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -290,12 +249,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-show-grants b/bin/pt-show-grants index 26d9fecd..c7a0ba92 100755 --- a/bin/pt-show-grants +++ b/bin/pt-show-grants @@ -1262,51 +1262,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1315,12 +1274,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-slave-delay b/bin/pt-slave-delay index d447503e..6004f4ca 100755 --- a/bin/pt-slave-delay +++ b/bin/pt-slave-delay @@ -1406,51 +1406,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1459,12 +1418,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-slave-find b/bin/pt-slave-find index de23b140..0877bd9b 100755 --- a/bin/pt-slave-find +++ b/bin/pt-slave-find @@ -1262,51 +1262,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1315,12 +1274,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-slave-restart b/bin/pt-slave-restart index 31e5d197..6ff05661 100755 --- a/bin/pt-slave-restart +++ b/bin/pt-slave-restart @@ -1525,51 +1525,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1578,12 +1537,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 5e8d2fea..a3a08ca8 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -237,51 +237,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -290,12 +249,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 2e4c953c..7ce6d6a0 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -1381,51 +1381,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1434,12 +1393,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-table-usage b/bin/pt-table-usage index f6f940e6..1bbaddf5 100755 --- a/bin/pt-table-usage +++ b/bin/pt-table-usage @@ -237,51 +237,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -290,12 +249,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-upgrade b/bin/pt-upgrade index 2d76e0bb..a65cacae 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -237,51 +237,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -290,12 +249,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-variable-advisor b/bin/pt-variable-advisor index e643c2de..de6fb7b7 100755 --- a/bin/pt-variable-advisor +++ b/bin/pt-variable-advisor @@ -1262,51 +1262,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1315,12 +1274,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref( diff --git a/bin/pt-visual-explain b/bin/pt-visual-explain index d0546df0..c2186dfe 100755 --- a/bin/pt-visual-explain +++ b/bin/pt-visual-explain @@ -1934,51 +1934,10 @@ sub get_dbh { PTDEBUG && _d($cxn_string, ' ', $user, ' ', $pass, join(', ', map { "$_=>$defaults->{$_}" } keys %$defaults )); - eval { - $dbh = DBI->connect($cxn_string, $user, $pass, $defaults); + $dbh = eval { DBI->connect($cxn_string, $user, $pass, $defaults) }; - if ( $cxn_string =~ m/mysql/i ) { - my $sql; - - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = $dbh->selectrow_array($sql); - - $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' - . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' - . ($sql_mode ? ",$sql_mode" : '') - . '\'*/'; - PTDEBUG && _d($dbh, $sql); - $dbh->do($sql); - - if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { - $sql = "/*!40101 SET NAMES $charset*/"; - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - PTDEBUG && _d('Enabling charset for STDOUT'); - if ( $charset eq 'utf8' ) { - binmode(STDOUT, ':utf8') - or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; - } - else { - binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; - } - } - - if ( $self->prop('set-vars') ) { - $sql = "SET " . $self->prop('set-vars'); - PTDEBUG && _d($dbh, ':', $sql); - $dbh->do($sql); - } - } - }; if ( !$dbh && $EVAL_ERROR ) { - PTDEBUG && _d($EVAL_ERROR); - if ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { - PTDEBUG && _d('Going to try again without utf8 support'); - delete $defaults->{mysql_enable_utf8}; - } - elsif ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { + if ( $EVAL_ERROR =~ m/locate DBD\/mysql/i ) { die "Cannot connect to MySQL because the Perl DBD::mysql module is " . "not installed or not found. Run 'perl -MDBD::mysql' to see " . "the directories that Perl searches for DBD::mysql. If " @@ -1987,12 +1946,63 @@ sub get_dbh { . " RHEL/CentOS yum install perl-DBD-MySQL\n" . " OpenSolaris pgk install pkg:/SUNWapu13dbd-mysql\n"; } + elsif ( $EVAL_ERROR =~ m/not a compiled character set|character set utf8/ ) { + PTDEBUG && _d('Going to try again without utf8 support'); + delete $defaults->{mysql_enable_utf8}; + } if ( !$tries ) { die $EVAL_ERROR; } } } + if ( $cxn_string =~ m/mysql/i ) { + my $sql; + + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' + . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' + . ($sql_mode ? ",$sql_mode" : '') + . '\'*/'; + PTDEBUG && _d($dbh, $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + + if ( my ($charset) = $cxn_string =~ m/charset=(\w+)/ ) { + $sql = "/*!40101 SET NAMES $charset*/"; + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + PTDEBUG && _d('Enabling charset for STDOUT'); + if ( $charset eq 'utf8' ) { + binmode(STDOUT, ':utf8') + or die "Can't binmode(STDOUT, ':utf8'): $OS_ERROR"; + } + else { + binmode(STDOUT) or die "Can't binmode(STDOUT): $OS_ERROR"; + } + } + + if ( $self->prop('set-vars') ) { + $sql = "SET " . $self->prop('set-vars'); + PTDEBUG && _d($dbh, ':', $sql); + eval { $dbh->do($sql) }; + if ( $EVAL_ERROR ) { + die $EVAL_ERROR; + } + } + } + PTDEBUG && _d('DBH info: ', $dbh, Dumper($dbh->selectrow_hashref(