-
-
Save tedtop/6144312 to your computer and use it in GitHub Desktop.
mysqldump filter -- Removes or replaces the DEFINER clauses from a dump (bug fix on line 32)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use Getopt::Long qw(:config no_ignore_case ); | |
my $replace = undef; | |
my $delete = undef; | |
my $help = 0; | |
GetOptions ( | |
'replace|r=s' => \$replace, | |
'delete|d' => \$delete, | |
'help|h' => \$help, | |
) or help('unrecognized options'); | |
help() if $help; | |
if ($delete and $replace) { | |
help( 'you must choose EITHER "delete" OR "replace". Not both'); | |
} | |
$delete = 1 unless $replace; | |
while (my $line = <STDIN>) { | |
if ($delete) { | |
$line =~ s{(/\*!\d+\s*)?definer\s*=\s*\S+\@\S+(\s*\*/)?}{}i; | |
} | |
elsif ($replace) { | |
$line =~ s{definer\s*=\s*(\S+\@\S+)}{$1 $replace}i; | |
} | |
print $line; | |
} | |
sub help { | |
my ($msg) = @_; | |
if ($msg) { | |
print "*** $msg\n"; | |
} | |
print "dump_filter - mysqldump filter \n", | |
"(C) Giuseppe Maxia, 2009\n", | |
"removes/changes DEFINER clauses from MySQL dumps\n", | |
"USAGE: dump_filter [options]\n", | |
" -d|--delete removes the DEFINER clauses\n", | |
" -r|--replace=s replaces every DEFINER clause with the \n", | |
" new value provided\n", | |
" -h|--help This text\n"; | |
exit(1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment