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";
30
GetOptions("force","help","host=s","password=s","user=s","type=s","verbose","version","socket=s", "port=i") ||
32
usage($opt_version) if ($#ARGV < 0 || $opt_help || $opt_version);
33
$opt_database=shift(@ARGV);
35
if (uc($opt_type) eq "HEAP")
37
print "Converting to type HEAP would delete your tables; aborting\n";
44
$connect_opt.= ";port=$opt_port";
46
if (length($opt_socket))
48
$connect_opt.=";mysql_socket=$opt_socket";
51
$dbh = DBI->connect("DBI:mysql:$opt_database:${opt_host}$connect_opt",
55
|| die "Can't connect to database $opt_database: $DBI::errstr\n";
59
# Fetch all table names from the database
61
$sth=$dbh->prepare("show tables");
62
$sth->execute || die "Can't get tables from $opt_database; $DBI::errstr\n";
63
while (($row = $sth->fetchrow_arrayref))
65
push(@ARGV,$row->[0]);
70
print "Converting tables:\n" if ($opt_verbose);
71
foreach $table (@ARGV)
75
# Check if table is already converted
76
$sth=$dbh->prepare("show table status like '$table'");
77
if ($sth->execute && ($row = $sth->fetchrow_arrayref))
79
if (uc($row->[1]) eq uc($opt_type))
81
print "$table is already of type $opt_type; Ignored\n";
85
print "converting $table\n" if ($opt_verbose);
86
if (!$dbh->do("ALTER TABLE $table ENGINE=$opt_type"))
88
print STDERR "Can't convert $table: Error $DBI::errstr\n";
89
exit(1) if (!$opt_force);
101
print "$0 version 1.1\n";
102
exit(0) if ($version);
106
Conversion of a MySQL tables to other table types.
108
Usage: $0 database [tables]
109
If no tables has been specifed, all tables in the database will be converted.
111
The following options are available:
114
Continue even if there is some error.
116
--help or --Information
119
--host='host name' (Default $opt_host)
120
Host name where the database server is located.
122
--password='password'
123
Password for the current user.
126
TCP/IP port to connect to if host is not "localhost".
128
--socket='/path/to/socket'
129
Socket to connect with.
131
--ENGINE='table-type'
132
Converts tables to the given table type (Default: $opt_type)
133
MySQL 3.23 supports at least the BDB, ISAM and MYISAM types.
136
User name to log into the SQL server.
139
This is a test specific option that is only used when debugging a test.
140
Print more information about what is going on.
143
Shows the version of this program.