mirror of
https://github.com/MariaDB/server.git
synced 2025-07-29 05:21:33 +03:00
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)
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user