Guest User

Untitled

a guest
Jan 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5.  
  6. sub options {
  7. die "usage: $0 <user> <password> <host> <database>\n" if scalar(@ARGV) != 4;
  8.  
  9. return {
  10. user => $ARGV[0],
  11. password => $ARGV[1],
  12. host => $ARGV[2],
  13. database => $ARGV[3],
  14. };
  15. }
  16. sub mysql_command {
  17. my $options = shift;
  18. my $command = "mysql -u $options->{user} ";
  19. $command .= "-p$options->{password} " if $options->{password};
  20. $command .= "-h $options->{host} " if $options->{host};
  21. $command .= "$options->{database}";
  22. return $command;
  23. }
  24. my $options = options();
  25.  
  26. my $command = "echo show tables | " . mysql_command($options);
  27. my @tables = split(/\s/, `$command`);
  28. for my $t (@tables) {
  29. print "=== $t ===\n";
  30. my $command = "echo show columns from $t | " . mysql_command($options);
  31. my @columns = split(/\n/, `$command`);
  32. for my $line (@columns) {
  33. print "$t\t$line\n";
  34. }
  35. print "\n";
  36. }
Add Comment
Please, Sign In to add comment