2
# Copyright (C) 2000-2002 MySQL AB
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
# Convert given tables in a database to MYISAM
22
$opt_help=$opt_version=$opt_verbose=$opt_force=0;
23
$opt_user=$opt_database=$opt_password=undef;
24
$opt_host="localhost";
31
"e|engine|type=s" => \$opt_type,
32
"f|force" => \$opt_force,
33
"help|?" => \$opt_help,
34
"h|host=s" => \$opt_host,
35
"p|password=s" => \$opt_password,
36
"u|user=s" => \$opt_user,
37
"v|verbose" => \$opt_verbose,
38
"V|version" => \$opt_version,
39
"S|socket=s" => \$opt_socket,
40
"P|port=i" => \$opt_port
43
usage($opt_version) if ($#ARGV < 0 || $opt_help || $opt_version);
45
$opt_database=shift(@ARGV);
47
if (grep { /^$opt_engine$/i } qw(HEAP MEMORY BLACKHOLE))
49
print "Converting to '$opt_engine' would delete your data; aborting\n";
56
$connect_opt.= ";port=$opt_port";
58
if (length($opt_socket))
60
$connect_opt.=";mysql_socket=$opt_socket";
63
$dbh = DBI->connect("DBI:mysql:$opt_database:${opt_host}$connect_opt",
67
|| die "Can't connect to database $opt_database: $DBI::errstr\n";
71
push(@ARGV, "%") if(!@ARGV);
73
foreach $pattern (@ARGV)
76
$sth=$dbh->prepare("SHOW TABLES LIKE ?");
77
$rv= $sth->execute($pattern);
80
warn "Can't get tables matching '$pattern' from $opt_database; $DBI::errstr\n";
81
exit(1) unless $opt_force;
83
while (($row = $sth->fetchrow_arrayref))
85
push(@tables, $row->[0]);
90
print "Converting tables:\n" if ($opt_verbose);
91
foreach $table (@tables)
95
# Check if table is already converted
96
$sth=$dbh->prepare("show table status like '$table'");
97
if ($sth->execute && ($row = $sth->fetchrow_arrayref))
99
if (uc($row->[1]) eq uc($opt_engine))
101
print "$table already uses the '$opt_engine' engine; Ignored\n";
105
print "converting $table\n" if ($opt_verbose);
107
if (!$dbh->do("ALTER TABLE `$table` ENGINE=$opt_engine"))
109
print STDERR "Can't convert $table: Error $DBI::errstr\n";
110
exit(1) if (!$opt_force);
122
print "$0 version 1.1\n";
123
exit(0) if ($version);
127
Conversion of a MySQL tables to other storage engines
129
Usage: $0 database [table[ table ...]]
130
If no tables has been specifed, all tables in the database will be converted.
131
You can also use wildcards, ie "my%"
133
The following options are available:
136
Continue even if there is some error.
142
Converts tables to the given storage engine (Default: $opt_engine)
145
Host name where the database server is located. (Default: $opt_host)
147
-p, --password=PASSWORD
148
Password for the current user.
151
TCP/IP port to connect to if host is not "localhost".
154
Socket to connect with.
157
User name to log into the SQL server.
160
This is a test specific option that is only used when debugging a test.
161
Print more information about what is going on.
164
Shows the version of this program.