diff --git a/bin/pt-archiver b/bin/pt-archiver index c7bec1d9..ce77e5a3 100755 --- a/bin/pt-archiver +++ b/bin/pt-archiver @@ -2514,13 +2514,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2542,6 +2535,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-config-diff b/bin/pt-config-diff index 33adb53c..fd5fa3b2 100755 --- a/bin/pt-config-diff +++ b/bin/pt-config-diff @@ -2077,13 +2077,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2105,6 +2098,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-deadlock-logger b/bin/pt-deadlock-logger index e75a9619..b8190aee 100755 --- a/bin/pt-deadlock-logger +++ b/bin/pt-deadlock-logger @@ -2421,13 +2421,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2449,6 +2442,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-duplicate-key-checker b/bin/pt-duplicate-key-checker index 04cf1488..95cf9319 100755 --- a/bin/pt-duplicate-key-checker +++ b/bin/pt-duplicate-key-checker @@ -916,13 +916,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -944,6 +937,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-find b/bin/pt-find index c1495316..4677a8b2 100755 --- a/bin/pt-find +++ b/bin/pt-find @@ -345,13 +345,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -373,6 +366,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-fk-error-logger b/bin/pt-fk-error-logger index 21efafcf..17ac9b46 100755 --- a/bin/pt-fk-error-logger +++ b/bin/pt-fk-error-logger @@ -1573,13 +1573,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -1601,6 +1594,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-heartbeat b/bin/pt-heartbeat index 0ea81008..25c10591 100755 --- a/bin/pt-heartbeat +++ b/bin/pt-heartbeat @@ -2814,13 +2814,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2842,6 +2835,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-index-usage b/bin/pt-index-usage index 53c82cfd..35393b3c 100755 --- a/bin/pt-index-usage +++ b/bin/pt-index-usage @@ -355,13 +355,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -383,6 +376,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-kill b/bin/pt-kill index 792c792e..7cdee6e8 100755 --- a/bin/pt-kill +++ b/bin/pt-kill @@ -2081,13 +2081,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2109,6 +2102,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-online-schema-change b/bin/pt-online-schema-change index b7510c1a..f2c2308a 100755 --- a/bin/pt-online-schema-change +++ b/bin/pt-online-schema-change @@ -2303,13 +2303,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2331,6 +2324,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') @@ -11741,6 +11741,15 @@ value of C<10000>. The tool prints a warning and continues if a variable cannot be set. +Note that setting the C variable requires some tricky escapes +to be able to parse the quotes and commas. + +Example: + + --set-vars sql_mode=\'STRICT_ALL_TABLES\\,ALLOW_INVALID_DATES\' + +Note the single backslash for the quotes and double backslash for the comma. + =item --sleep type: float; default: 0 diff --git a/bin/pt-query-digest b/bin/pt-query-digest index 9087d4a7..bef1a88b 100755 --- a/bin/pt-query-digest +++ b/bin/pt-query-digest @@ -1023,13 +1023,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -1051,6 +1044,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-show-grants b/bin/pt-show-grants index 9b4ad58f..69be9346 100755 --- a/bin/pt-show-grants +++ b/bin/pt-show-grants @@ -1360,13 +1360,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -1388,6 +1381,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-slave-delay b/bin/pt-slave-delay index fb038b3f..2373c196 100755 --- a/bin/pt-slave-delay +++ b/bin/pt-slave-delay @@ -2074,13 +2074,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2102,6 +2095,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-slave-find b/bin/pt-slave-find index 628d5457..c2b09f46 100755 --- a/bin/pt-slave-find +++ b/bin/pt-slave-find @@ -2017,13 +2017,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2045,6 +2038,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-slave-restart b/bin/pt-slave-restart index 3189ec4c..0ba294c9 100755 --- a/bin/pt-slave-restart +++ b/bin/pt-slave-restart @@ -2420,13 +2420,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2448,6 +2441,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 032a2ab3..770b2033 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -1603,13 +1603,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -1631,6 +1624,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 4b943358..0c663241 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -2242,13 +2242,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2270,6 +2263,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-table-usage b/bin/pt-table-usage index 6e317733..ea492642 100755 --- a/bin/pt-table-usage +++ b/bin/pt-table-usage @@ -24,10 +24,10 @@ BEGIN { Transformers QueryRewriter QueryParser + VersionParser FileIterator SQLParser TableUsage - VersionParser Daemon Runtime Progress @@ -297,13 +297,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -325,6 +318,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-upgrade b/bin/pt-upgrade index ee225fcb..a75ef503 100755 --- a/bin/pt-upgrade +++ b/bin/pt-upgrade @@ -1020,13 +1020,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -1048,6 +1041,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-variable-advisor b/bin/pt-variable-advisor index 2b4d0733..ab69933a 100755 --- a/bin/pt-variable-advisor +++ b/bin/pt-variable-advisor @@ -2078,13 +2078,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2106,6 +2099,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/bin/pt-visual-explain b/bin/pt-visual-explain index 36abdc63..98e6aa4c 100755 --- a/bin/pt-visual-explain +++ b/bin/pt-visual-explain @@ -2034,13 +2034,6 @@ sub get_dbh { 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 "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; PTDEBUG && _d($dbh, $sql); @@ -2062,6 +2055,13 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' . '/*!40101, @@SQL_MODE=\'NO_AUTO_VALUE_ON_ZERO' . ($sql_mode ? ",$sql_mode" : '') diff --git a/lib/DSNParser.pm b/lib/DSNParser.pm index 6d9249fe..9ec39bd3 100644 --- a/lib/DSNParser.pm +++ b/lib/DSNParser.pm @@ -332,17 +332,6 @@ sub get_dbh { if ( $cxn_string =~ m/mysql/i ) { my $sql; - # Set SQL_MODE and options for SHOW CREATE TABLE. - # Get current, server SQL mode. Don't clobber this; - # append our SQL mode to whatever is already set. - # http://code.google.com/p/maatkit/issues/detail?id=801 - $sql = 'SELECT @@SQL_MODE'; - PTDEBUG && _d($dbh, $sql); - my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; - if ( $EVAL_ERROR ) { - die "Error getting the current SQL_MODE: $EVAL_ERROR"; - } - # Set character set and binmode on STDOUT. if ( my ($charset) = $cxn_string =~ m/charset=([\w]+)/ ) { $sql = qq{/*!40101 SET NAMES "$charset"*/}; @@ -365,6 +354,17 @@ sub get_dbh { $self->set_vars($dbh, $vars); } + # Set SQL_MODE and options for SHOW CREATE TABLE. + # Get current, server SQL mode. Don't clobber this; + # append our SQL mode to whatever is already set. + # http://code.google.com/p/maatkit/issues/detail?id=801 + $sql = 'SELECT @@SQL_MODE'; + PTDEBUG && _d($dbh, $sql); + my ($sql_mode) = eval { $dbh->selectrow_array($sql) }; + if ( $EVAL_ERROR ) { + die "Error getting the current SQL_MODE: $EVAL_ERROR"; + } + # Do this after set-vars so a user-set sql_mode doesn't clobber it; See # https://bugs.launchpad.net/percona-toolkit/+bug/1078887 $sql = 'SET @@SQL_QUOTE_SHOW_CREATE = 1' diff --git a/t/pt-online-schema-change/basics.t b/t/pt-online-schema-change/basics.t index facc8dda..07ef0212 100644 --- a/t/pt-online-schema-change/basics.t +++ b/t/pt-online-schema-change/basics.t @@ -46,7 +46,6 @@ my $exit = 0; my $sample = "t/pt-online-schema-change/samples"; my $rows; - # ############################################################################# # Tool shouldn't run without --execute (bug 933232). # ############################################################################# @@ -686,7 +685,6 @@ test_alter_table( ], ); - # ############################################################################# # --statistics # ############################################################################# @@ -709,7 +707,7 @@ my $res_file = "$sample/stats-execute.txt"; if ($sandbox_version eq '5.5' && $db_flavor !~ m/XtraDB Cluster/) { $res_file = "$sample/stats-execute-5.5.txt"; } elsif ($sandbox_version eq '5.6' && $db_flavor !~ m/XtraDB Cluster/) { - $res_file = "$sample/stats-execute.txt"; + $res_file = "$sample/stats-execute-5.6.txt"; } elsif ($sandbox_version eq '5.7' && $db_flavor !~ m/XtraDB Cluster/) { $res_file = "$sample/stats-execute-5.7.txt"; } @@ -723,10 +721,12 @@ ok( '--recursion-method', 'none'), }, $res_file, + keep_output=>1, ), "--statistics --execute" ) or diag($test_diff); + # ############################################################################# # --chunk-size-limit=0 must not skip tables that would be chunked # in one nibble diff --git a/t/pt-online-schema-change/bugs.t b/t/pt-online-schema-change/bugs.t index 056e097d..3a2b0323 100644 --- a/t/pt-online-schema-change/bugs.t +++ b/t/pt-online-schema-change/bugs.t @@ -14,7 +14,7 @@ use Test::More; use Data::Dumper; use PerconaTest; use Sandbox; - +use SqlModes; require "$trunk/bin/pt-online-schema-change"; my $dp = new DSNParser(opts=>$dsn_opts); @@ -38,6 +38,7 @@ my $output; my $exit_status; my $sample = "t/pt-online-schema-change/samples/"; + # ############################################################################ # https://bugs.launchpad.net/percona-toolkit/+bug/1336734 # pt-online-schema-change 2.2.17 adds --null-to-not-null feature @@ -510,6 +511,39 @@ like( "Bug 1446928: Avoid error trapping loop when --alter is invalid", ); +# ############################################################################ +# https://bugs.launchpad.net/percona-toolkit/+bug/1506748 +# test that setting sql_mode via --set-vars works +# ############################################################################ + +# first we create a table with a valid default date +$sb->load_file('master', "$sample/sql_mode_issue_lp1506748.sql"); + +my $modes = new SqlModes($master_dbh, global =>1); + +# We clear all modes. In this state, setting an invalid default date generates +# an error. +$modes->set_mode_string(''); + +# Now we run the command, but set sql_mode to allow invalid dates for +# the session. +# While we're at it, test that we can set more than one mode by double escaping +# the commas. (must be explained in docs) +($output, $exit_status) = full_output( + sub { pt_online_schema_change::main(@args, + "$master_dsn,D=test,t=lp1506748", + "--execute", + "--set-vars", "sql_mode=\'STRICT_ALL_TABLES\\,ALLOW_INVALID_DATES\'", + "--alter", "MODIFY COLUMN birthday DATE DEFAULT '1970-02-31'", + ) }, +); + +ok ((!$exit_status && $output =~ /success/i) , "--set-vars sql_mode=\\'a\\\\,b\\' works" ) + or diag("[$output][$exit_status]"); + +$master_dbh->do("drop database test"); +$modes->restore_original_modes(); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-online-schema-change/samples/sql_mode_issue_lp1506748.sql b/t/pt-online-schema-change/samples/sql_mode_issue_lp1506748.sql new file mode 100644 index 00000000..77ddde37 --- /dev/null +++ b/t/pt-online-schema-change/samples/sql_mode_issue_lp1506748.sql @@ -0,0 +1,4 @@ +create database if not exists test; +create table if not exists test.lp1506748 (id int PRIMARY KEY, birthday date default '1970-01-01'); + + diff --git a/t/pt-online-schema-change/samples/stats-execute-5.6.txt b/t/pt-online-schema-change/samples/stats-execute-5.6.txt new file mode 100644 index 00000000..47e7cd67 --- /dev/null +++ b/t/pt-online-schema-change/samples/stats-execute-5.6.txt @@ -0,0 +1,30 @@ +No slaves found. See --recursion-method if host h=127.1,P=12345 has slaves. +Not checking slave lag because no slaves were found and --check-slave-lag was not specified. +Operation, tries, wait: + analyze_table, 10, 1 + copy_rows, 10, 0.25 + create_triggers, 10, 1 + drop_triggers, 10, 1 + swap_tables, 10, 1 + update_foreign_keys, 10, 1 +Altering `bug_1045317`.`bits`... +TS Dropping triggers... +TS Dropped triggers OK. +# Event Count +# ================== ===== +# INSERT 1 +# mysql_warning_1592 1 +Successfully altered `bug_1045317`.`bits`. +Creating new table... +Created new table bug_1045317._bits_new OK. +Altering new table... +Altered `bug_1045317`.`_bits_new` OK. +TS Creating triggers... +TS Created triggers OK. +TS Copying approximately 3 rows... +TS Copied rows OK. +TS Analyzing new table... +TS Swapping tables... +TS Swapped original and new tables OK. +TS Dropping old table... +TS Dropped old table `bug_1045317`.`_bits_old` OK. diff --git a/t/pt-table-checksum/progress.t b/t/pt-table-checksum/progress.t index a32556ba..af6a116f 100644 --- a/t/pt-table-checksum/progress.t +++ b/t/pt-table-checksum/progress.t @@ -48,7 +48,7 @@ else { # worse. This is a random stab in the dark. There is a problem either way.) my $master_dsn = 'h=127.1,P=12345,u=msandbox,p=msandbox'; my @args = ($master_dsn, qw(--set-vars innodb_lock_wait_timeout=3), - '--progress', 'time,1', '--max-load', '', '--chunk-size', '500'); + '--progress', 'time,2', '--max-load', '', '--chunk-size', '500'); my $output; my $row; my $scripts = "$trunk/t/pt-table-checksum/scripts/";