diff options
author | Jim Winstead <jimw@mysql.com> | 2009-04-28 11:47:34 -0700 |
---|---|---|
committer | Jim Winstead <jimw@mysql.com> | 2009-04-28 11:47:34 -0700 |
commit | f72fd8fe219ef362a241206117b038df92c97b57 (patch) | |
tree | e145402203145c259f56fa6b660d58ce837961b8 /scripts | |
parent | 39e4b5ebd23742bfcf65e61d586aaa6f9191cc17 (diff) | |
download | mariadb-git-f72fd8fe219ef362a241206117b038df92c97b57.tar.gz |
Add support for wildcards in mysql_convert_table_format, and add
short options for all of the long options. (Bug #30373, original
contribution by Tobias Asplund)
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/mysql_convert_table_format.sh | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/scripts/mysql_convert_table_format.sh b/scripts/mysql_convert_table_format.sh index e49c702d1df..6f586d0e8e0 100644 --- a/scripts/mysql_convert_table_format.sh +++ b/scripts/mysql_convert_table_format.sh @@ -27,9 +27,21 @@ $opt_engine="MYISAM"; $opt_port=0; $exit_status=0; -GetOptions("force","help","host=s","password=s","user=s","engine|type=s","verbose","version","socket=s", "port=i") || - usage(0); +GetOptions( + "e|engine|type=s" => \$opt_type, + "f|force" => \$opt_force, + "help|?" => \$opt_help, + "h|host=s" => \$opt_host, + "p|password=s" => \$opt_password, + "u|user=s" => \$opt_user, + "v|verbose" => \$opt_verbose, + "V|version" => \$opt_version, + "S|socket=s" => \$opt_socket, + "P|port=i" => \$opt_port +) || usage(0); + usage($opt_version) if ($#ARGV < 0 || $opt_help || $opt_version); + $opt_database=shift(@ARGV); if (grep { /^$opt_engine$/i } qw(HEAP MEMORY BLACKHOLE)) @@ -54,21 +66,29 @@ $dbh = DBI->connect("DBI:mysql:$opt_database:${opt_host}$connect_opt", { PrintError => 0}) || die "Can't connect to database $opt_database: $DBI::errstr\n"; -if ($#ARGV < 0) +my @tables; + +push(@ARGV, "%") if(!@ARGV); + +foreach $pattern (@ARGV) { - # Fetch all table names from the database my ($sth,$row); - $sth=$dbh->prepare("show tables"); - $sth->execute || die "Can't get tables from $opt_database; $DBI::errstr\n"; + $sth=$dbh->prepare("SHOW TABLES LIKE ?"); + $rv= $sth->execute($pattern); + if(!int($rv)) + { + warn "Can't get tables matching '$pattern' from $opt_database; $DBI::errstr\n"; + exit(1) unless $opt_force; + } while (($row = $sth->fetchrow_arrayref)) { - push(@ARGV,$row->[0]); + push(@tables, $row->[0]); } $sth->finish; } print "Converting tables:\n" if ($opt_verbose); -foreach $table (@ARGV) +foreach $table (@tables) { my ($sth,$row); @@ -106,40 +126,41 @@ sub usage Conversion of a MySQL tables to other storage engines - Usage: $0 database [tables] + Usage: $0 database [table[ table ...]] If no tables has been specifed, all tables in the database will be converted. + You can also use wildcards, ie "my%" The following options are available: ---force +-f, --force Continue even if there is some error. ---help +-?, --help Shows this help ---engine='engine' +-e, --engine=ENGINE Converts tables to the given storage engine (Default: $opt_engine) ---host='host name' (Default $opt_host) - Host name where the database server is located. +-h, --host=HOST + Host name where the database server is located. (Default: $opt_host) ---password='password' +-p, --password=PASSWORD Password for the current user. ---port=port +-P, --port=PORT TCP/IP port to connect to if host is not "localhost". ---socket='/path/to/socket' +-S, --socket=SOCKET Socket to connect with. ---user='user_name' +-u, --user=USER User name to log into the SQL server. ---verbose +-v, --verbose This is a test specific option that is only used when debugging a test. Print more information about what is going on. ---version +-V, --version Shows the version of this program. EOF exit(1); |