PT-1563 Fixed pt-show-grants for MySQL 5.6

Also updated tests for MySQL 8.0+
This commit is contained in:
Carlos Salguero
2018-05-28 15:29:18 -03:00
parent b2decb0f82
commit 7666af3fbb
5 changed files with 15 additions and 15 deletions

View File

@@ -1912,11 +1912,14 @@ sub main {
# MySQL 8 roles must be excluded from the regular users list.
# Roles can be identified because the user password is expired, the authentication
# string is empty and the account is locked
my $mysql8_where = '';
if (VersionCompare::cmp($version, '8.0.0') >= 0) {
$mysql8_where = ' WHERE NOT ( `account_locked`="Y" AND ' .
' `password_expired`="Y" AND ' .
' `authentication_string`="" ) ';
}
my $users = $o->get('only') || $dbh->selectall_arrayref(
'SELECT DISTINCT User, Host FROM mysql.user WHERE NOT (`account_locked`="Y"
AND `password_expired`="Y"
AND `authentication_string`=""
) ORDER BY User, Host',
"SELECT DISTINCT User, Host FROM mysql.user $mysql8_where ORDER BY User, Host",
{ Slice => {} });
if ( scalar @all_hosts ) {
my $where = join(' OR ', map { "User='$_'" } @all_hosts);

View File

@@ -38,9 +38,11 @@ my $cnf = '/tmp/12345/my.sandbox.cnf';
# user (over multiple hosts)
# #############################################################################
# to make creating users easier we remove NO_AUTO_CREATE_USER mode
my $modes = new SqlModes($dbh, global=>1);
$modes->del('NO_AUTO_CREATE_USER');
diag(`/tmp/12345/use -u root -e "CREATE USER 'bob'\@'%'"`);
diag(`/tmp/12345/use -u root -e "CREATE USER 'bob'\@'localhost'"`);
diag(`/tmp/12345/use -u root -e "CREATE USER 'bob'\@'192.168.1.1'"`);
diag(`/tmp/12345/use -u root -e "GRANT USAGE ON *.* TO 'bob'\@'%'"`);
diag(`/tmp/12345/use -u root -e "GRANT USAGE ON *.* TO 'bob'\@'localhost'"`);
diag(`/tmp/12345/use -u root -e "GRANT USAGE ON *.* TO 'bob'\@'192.168.1.1'"`);

View File

@@ -83,7 +83,7 @@ unlike(
);
$output = output(
sub { pt_show_grants::main('-F', $cnf, '--ignore', 'baron,msandbox,root,root@localhost,user,mysql.session@localhost,mysql.sys@localhost,sys'); }
sub { pt_show_grants::main('-F', $cnf, '--ignore', 'baron,msandbox,root,root@localhost,user,mysql.session@localhost,mysql.sys@localhost,sys,mysql.infoschema@localhost'); }
);
unlike(
$output,
@@ -100,12 +100,9 @@ like(
# https://bugs.launchpad.net/percona-toolkit/+bug/866075
# #############################################################################
$sb->load_file('master', 't/pt-show-grants/samples/column-grants.sql');
# momentarily disable NO_AUTO_CREATE_USER
my $modes = new SqlModes($dbh, global=>1);
$modes->del('NO_AUTO_CREATE_USER');
diag(`/tmp/12345/use -u root -e "CREATE USER 'sally'\@'%'"`);
diag(`/tmp/12345/use -u root -e "GRANT SELECT(DateCreated, PckPrice, PaymentStat, SANumber) ON test.t TO 'sally'\@'%'"`);
diag(`/tmp/12345/use -u root -e "GRANT SELECT(city_id), INSERT(city) ON sakila.city TO 'sally'\@'%'"`);
$modes->restore_original_modes();
my $postfix = $sandbox_version >= '8.0' ? '-80' : $sandbox_version < '5.7' ? '' : '-57';

View File

@@ -37,10 +37,8 @@ my $cnf = '/tmp/12345/my.sandbox.cnf';
# #############################################################################
# allow auto create user for a moment
my $modes = new SqlModes($dbh, global=>1);
$modes->del('NO_AUTO_CREATE_USER');
diag(`/tmp/12345/use -u root -e "CREATE USER ''\@''"`);
diag(`/tmp/12345/use -u root -e "GRANT USAGE ON *.* TO ''\@''"`);
$modes->restore_original_modes();
$output = `/tmp/12345/use -e "SELECT user FROM mysql.user WHERE user = ''"`;
like(

View File

@@ -6,7 +6,7 @@ CREATE TABLE t (
`SOrNum` mediumint(9) unsigned NOT NULL auto_increment,
`SPNum` mediumint(9) unsigned NOT NULL,
`DateCreated` timestamp NOT NULL default CURRENT_TIMESTAMP,
`DateRelease` timestamp NOT NULL default CURRENT_TIMESTAMP,
`DateRelease` timestamp NOT NULL,
`ActualReleasedDate` timestamp NULL default NULL,
`PckPrice` decimal(10,2) NOT NULL default '0.00',
`Status` varchar(20) NOT NULL,