-
-
Save erincerys/5470883 to your computer and use it in GitHub Desktop.
MySQLdump filter -- Removes or replaces the DEFINER clauses from a dump
This file contains hidden or 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) { | |
# Forked to | |
# - remove /*!\s portion of DEFINER | |
# - handle view SQL SECURITY DEFINERs | |
# - match variances of whitespace | |
$line =~ s{(/\*!\d+\s*)?definer\s*=\s*\S+\@\S+(\s*sql\ssecurity\sdefiner\s*)?(\s*\*/)?}{}i; | |
} | |
elsif ($replace) { | |
# Incorporates bugfix from tedtop's fork | |
$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
https://gist.github.com/toporkov/6144312 fixes a bug on line 32