Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use warnings;
- use utf8;
- sub options {
- die "usage: $0 <user> <password> <host> <database>\n" if scalar(@ARGV) != 4;
- return {
- user => $ARGV[0],
- password => $ARGV[1],
- host => $ARGV[2],
- database => $ARGV[3],
- };
- }
- sub mysql_command {
- my $options = shift;
- my $command = "mysql -u $options->{user} ";
- $command .= "-p$options->{password} " if $options->{password};
- $command .= "-h $options->{host} " if $options->{host};
- $command .= "$options->{database}";
- return $command;
- }
- my $options = options();
- my $command = "echo show tables | " . mysql_command($options);
- my @tables = split(/\s/, `$command`);
- for my $t (@tables) {
- print "=== $t ===\n";
- my $command = "echo show columns from $t | " . mysql_command($options);
- my @columns = split(/\n/, `$command`);
- for my $line (@columns) {
- print "$t\t$line\n";
- }
- print "\n";
- }
Add Comment
Please, Sign In to add comment