1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
/* By Jani Tolonen, 2001-04-20, MySQL Development Team */
18
#define CHECK_VERSION "2.5.0"
20
#include "client_priv.h"
22
#include <mysql_version.h>
23
#include <mysqld_error.h>
30
static MYSQL mysql_connection, *sock = 0;
31
static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0,
32
opt_compress = 0, opt_databases = 0, opt_fast = 0,
33
opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 0,
34
opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0,
35
tty_password= 0, opt_frm= 0, debug_info_flag= 0, debug_check_flag= 0,
36
opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0,
38
static uint verbose = 0, opt_mysql_port=0;
39
static int my_end_arg;
40
static char * opt_mysql_unix_port = 0;
41
static char *opt_password = 0, *current_user = 0,
42
*default_charset = (char *)MYSQL_DEFAULT_CHARSET_NAME,
44
static int first_error = 0;
45
DYNAMIC_ARRAY tables4repair;
47
static char *shared_memory_base_name=0;
49
static uint opt_protocol=0;
50
static CHARSET_INFO *charset_info= &my_charset_latin1;
52
enum operations { DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE };
54
static struct my_option my_long_options[] =
56
{"all-databases", 'A',
57
"Check all the databases. This will be same as --databases with all databases selected.",
58
(uchar**) &opt_alldbs, (uchar**) &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0,
60
{"analyze", 'a', "Analyze given tables.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
63
"Instead of issuing one query for each table, use one query per database, naming all tables in the database in a comma-separated list.",
64
(uchar**) &opt_all_in_1, (uchar**) &opt_all_in_1, 0, GET_BOOL, NO_ARG, 0, 0, 0,
66
{"auto-repair", OPT_AUTO_REPAIR,
67
"If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",
68
(uchar**) &opt_auto_repair, (uchar**) &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0,
70
{"character-sets-dir", OPT_CHARSETS_DIR,
71
"Directory where character sets are.", (uchar**) &charsets_dir,
72
(uchar**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
73
{"check", 'c', "Check table for errors.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0,
75
{"check-only-changed", 'C',
76
"Check only tables that have changed since last check or haven't been closed properly.",
77
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
78
{"check-upgrade", 'g',
79
"Check tables for version-dependent changes. May be used with --auto-repair to correct tables requiring version-dependent updates.",
80
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
81
{"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
82
(uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
85
"To check several databases. Note the difference in usage; In this case no tables are given. All name arguments are regarded as databasenames.",
86
(uchar**) &opt_databases, (uchar**) &opt_databases, 0, GET_BOOL, NO_ARG,
89
{"debug", '#', "This is a non-debug version. Catch this and exit.",
90
0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
92
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.",
93
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
95
{"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
96
(uchar**) &debug_check_flag, (uchar**) &debug_check_flag, 0,
97
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
98
{"debug-info", OPT_DEBUG_INFO, "Print some debug info at exit.",
99
(uchar**) &debug_info_flag, (uchar**) &debug_info_flag,
100
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
101
{"default-character-set", OPT_DEFAULT_CHARSET,
102
"Set the default character set.", (uchar**) &default_charset,
103
(uchar**) &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
104
{"fast",'F', "Check only tables that haven't been closed properly.",
105
(uchar**) &opt_fast, (uchar**) &opt_fast, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
107
{"fix-db-names", OPT_FIX_DB_NAMES, "Fix database names.",
108
(uchar**) &opt_fix_db_names, (uchar**) &opt_fix_db_names,
109
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
110
{"fix-table-names", OPT_FIX_TABLE_NAMES, "Fix table names.",
111
(uchar**) &opt_fix_table_names, (uchar**) &opt_fix_table_names,
112
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
113
{"force", 'f', "Continue even if we get an sql-error.",
114
(uchar**) &ignore_errors, (uchar**) &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0,
117
"If you are using this option with CHECK TABLE, it will ensure that the table is 100 percent consistent, but will take a long time. If you are using this option with REPAIR TABLE, it will force using old slow repair with keycache method, instead of much faster repair by sorting.",
118
(uchar**) &opt_extended, (uchar**) &opt_extended, 0, GET_BOOL, NO_ARG, 0, 0, 0,
120
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
121
NO_ARG, 0, 0, 0, 0, 0, 0},
122
{"host",'h', "Connect to host.", (uchar**) ¤t_host,
123
(uchar**) ¤t_host, 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
124
{"medium-check", 'm',
125
"Faster than extended-check, but only finds 99.99 percent of all errors. Should be good enough for most cases.",
126
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
127
{"write-binlog", OPT_WRITE_BINLOG,
128
"Log ANALYZE, OPTIMIZE and REPAIR TABLE commands. Use --skip-write-binlog when commands should not be sent to replication slaves.",
129
(uchar**) &opt_write_binlog, (uchar**) &opt_write_binlog, 0, GET_BOOL, NO_ARG,
131
{"optimize", 'o', "Optimize table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0,
134
"Password to use when connecting to server. If password is not given it's solicited on the tty.",
135
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
136
{"port", 'P', "Port number to use for connection or 0 for default to, in "
137
"order of preference, my.cnf, $MYSQL_TCP_PORT, "
138
#if MYSQL_PORT_DEFAULT == 0
141
"built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
142
(uchar**) &opt_mysql_port,
143
(uchar**) &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
145
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol of connection (tcp,socket,pipe,memory).",
146
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
148
"If you are using this option with CHECK TABLE, it prevents the check from scanning the rows to check for wrong links. This is the fastest check. If you are using this option with REPAIR TABLE, it will try to repair only the index tree. This is the fastest repair method for a table.",
149
(uchar**) &opt_quick, (uchar**) &opt_quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
152
"Can fix almost anything except unique keys that aren't unique.",
153
0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
155
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
156
"Base name of shared memory.", (uchar**) &shared_memory_base_name, (uchar**) &shared_memory_base_name,
157
0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
159
{"silent", 's', "Print only error messages.", (uchar**) &opt_silent,
160
(uchar**) &opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
161
{"socket", 'S', "Socket file to use for connection.",
162
(uchar**) &opt_mysql_unix_port, (uchar**) &opt_mysql_unix_port, 0, GET_STR,
163
REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
164
{"tables", OPT_TABLES, "Overrides option --databases (-B).", 0, 0, 0,
165
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
167
"When used with REPAIR, get table structure from .frm file, so the table can be repaired even if .MYI header is corrupted.",
168
(uchar**) &opt_frm, (uchar**) &opt_frm, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0,
170
#ifndef DONT_ALLOW_USER_CHANGE
171
{"user", 'u', "User for login if not current user.", (uchar**) ¤t_user,
172
(uchar**) ¤t_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
174
{"verbose", 'v', "Print info about the various stages.", 0, 0, 0, GET_NO_ARG,
175
NO_ARG, 0, 0, 0, 0, 0, 0},
176
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
177
NO_ARG, 0, 0, 0, 0, 0, 0},
178
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
181
static const char *load_default_groups[] = { "mysqlcheck", "client", 0 };
184
static void print_version(void);
185
static void usage(void);
186
static int get_options(int *argc, char ***argv);
187
static int process_all_databases();
188
static int process_databases(char **db_names);
189
static int process_selected_tables(char *db, char **table_names, int tables);
190
static int process_all_tables_in_db(char *database);
191
static int process_one_db(char *database);
192
static int use_db(char *database);
193
static int handle_request_for_tables(char *tables, uint length);
194
static int dbConnect(char *host, char *user,char *passwd);
195
static void dbDisconnect(char *host);
196
static void DBerror(MYSQL *mysql, const char *when);
197
static void safe_exit(int error);
198
static void print_result();
199
static uint fixed_name_length(const char *name);
200
static char *fix_table_name(char *dest, char *src);
203
#include <help_start.h>
205
static void print_version(void)
207
printf("%s Ver %s Distrib %s, for %s (%s)\n", my_progname, CHECK_VERSION,
208
MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
209
} /* print_version */
212
static void usage(void)
215
puts("By Jani Tolonen, 2001-04-20, MySQL Development Team\n");
216
puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n");
217
puts("and you are welcome to modify and redistribute it under the GPL license.\n");
218
puts("This program can be used to CHECK (-c,-m,-C), REPAIR (-r), ANALYZE (-a)");
219
puts("or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be");
220
puts("used at the same time. Not all options are supported by all storage engines.");
221
puts("Please consult the MySQL manual for latest information about the");
222
puts("above. The options -c,-r,-a and -o are exclusive to each other, which");
223
puts("means that the last option will be used, if several was specified.\n");
224
puts("The option -c will be used by default, if none was specified. You");
225
puts("can change the default behavior by making a symbolic link, or");
226
puts("copying this file somewhere with another name, the alternatives are:");
227
puts("mysqlrepair: The default option will be -r");
228
puts("mysqlanalyze: The default option will be -a");
229
puts("mysqloptimize: The default option will be -o\n");
230
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
231
printf("OR %s [OPTIONS] --databases DB1 [DB2 DB3...]\n",
233
printf("OR %s [OPTIONS] --all-databases\n", my_progname);
234
print_defaults("my", load_default_groups);
235
my_print_help(my_long_options);
236
my_print_variables(my_long_options);
239
#include <help_end.h>
242
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
247
what_to_do = DO_ANALYZE;
250
what_to_do = DO_CHECK;
253
what_to_do = DO_CHECK;
254
opt_check_only_changed = 1;
256
case 'I': /* Fall through */
261
what_to_do = DO_CHECK;
262
opt_medium_check = 1;
265
what_to_do = DO_OPTIMIZE;
267
case OPT_FIX_DB_NAMES:
268
what_to_do= DO_UPGRADE;
269
default_charset= (char*) "utf8";
272
case OPT_FIX_TABLE_NAMES:
273
what_to_do= DO_UPGRADE;
274
default_charset= (char*) "utf8";
279
char *start = argument;
280
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
281
opt_password = my_strdup(argument, MYF(MY_FAE));
282
while (*argument) *argument++= 'x'; /* Destroy argument */
284
start[1] = 0; /* Cut length of argument */
291
what_to_do = DO_REPAIR;
294
what_to_do= DO_CHECK;
298
DBUG_PUSH(argument ? argument : "d:t:o");
307
case 'V': print_version(); exit(0);
308
case OPT_MYSQL_PROTOCOL:
309
opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
317
static int get_options(int *argc, char ***argv)
327
load_defaults("my", load_default_groups, argc, argv);
329
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option)))
334
int pnlen = strlen(my_progname);
336
if (pnlen < 6) /* name too short */
337
what_to_do = DO_CHECK;
338
else if (!strcmp("repair", my_progname + pnlen - 6))
339
what_to_do = DO_REPAIR;
340
else if (!strcmp("analyze", my_progname + pnlen - 7))
341
what_to_do = DO_ANALYZE;
342
else if (!strcmp("optimize", my_progname + pnlen - 8))
343
what_to_do = DO_OPTIMIZE;
345
what_to_do = DO_CHECK;
348
/* TODO: This variable is not yet used */
349
if (strcmp(default_charset, charset_info->csname) &&
350
!(charset_info= get_charset_by_csname(default_charset,
351
MY_CS_PRIMARY, MYF(MY_WME))))
353
if (*argc > 0 && opt_alldbs)
355
printf("You should give only options, no arguments at all, with option\n");
356
printf("--all-databases. Please see %s --help for more information.\n",
360
if (*argc < 1 && !opt_alldbs)
362
printf("You forgot to give the arguments! Please see %s --help\n",
364
printf("for more information.\n");
368
opt_password = get_tty_password(NullS);
370
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
371
if (debug_check_flag)
372
my_end_arg= MY_CHECK_ERROR;
377
static int process_all_databases()
383
if (mysql_query(sock, "SHOW DATABASES") ||
384
!(tableres = mysql_store_result(sock)))
386
my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s",
387
MYF(0), mysql_error(sock));
390
while ((row = mysql_fetch_row(tableres)))
392
if (process_one_db(row[0]))
397
/* process_all_databases */
400
static int process_databases(char **db_names)
403
for ( ; *db_names ; db_names++)
405
if (process_one_db(*db_names))
409
} /* process_databases */
412
static int process_selected_tables(char *db, char **table_names, int tables)
419
We need table list in form `a`, `b`, `c`
420
that's why we need 2 more chars added to to each table name
421
space is for more readable output in logs and in case of error
423
char *table_names_comma_sep, *end;
424
int i, tot_length = 0;
426
for (i = 0; i < tables; i++)
427
tot_length+= fixed_name_length(*(table_names + i)) + 2;
429
if (!(table_names_comma_sep = (char *)
430
my_malloc((sizeof(char) * tot_length) + 4, MYF(MY_WME))))
433
for (end = table_names_comma_sep + 1; tables > 0;
434
tables--, table_names++)
436
end= fix_table_name(end, *table_names);
440
handle_request_for_tables(table_names_comma_sep + 1, tot_length - 1);
441
my_free(table_names_comma_sep, MYF(0));
444
for (; tables > 0; tables--, table_names++)
445
handle_request_for_tables(*table_names, fixed_name_length(*table_names));
447
} /* process_selected_tables */
450
static uint fixed_name_length(const char *name)
453
uint extra_length= 2; /* count the first/last backticks */
455
for (p= name; *p; p++)
462
return (p - name) + extra_length;
466
static char *fix_table_name(char *dest, char *src)
472
case '.': /* add backticks around '.' */
477
case '`': /* escape backtick character */
489
static int process_all_tables_in_db(char *database)
495
if (use_db(database))
497
if (mysql_query(sock, "SHOW /*!50002 FULL*/ TABLES") ||
498
!((res= mysql_store_result(sock))))
501
num_columns= mysql_num_fields(res);
506
We need table list in form `a`, `b`, `c`
507
that's why we need 2 more chars added to to each table name
508
space is for more readable output in logs and in case of error
514
while ((row = mysql_fetch_row(res)))
515
tot_length+= fixed_name_length(row[0]) + 2;
516
mysql_data_seek(res, 0);
518
if (!(tables=(char *) my_malloc(sizeof(char)*tot_length+4, MYF(MY_WME))))
520
mysql_free_result(res);
523
for (end = tables + 1; (row = mysql_fetch_row(res)) ;)
525
if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
528
end= fix_table_name(end, row[0]);
533
handle_request_for_tables(tables + 1, tot_length - 1);
534
my_free(tables, MYF(0));
538
while ((row = mysql_fetch_row(res)))
540
/* Skip views if we don't perform renaming. */
541
if ((what_to_do != DO_UPGRADE) && (num_columns == 2) && (strcmp(row[1], "VIEW") == 0))
544
handle_request_for_tables(row[0], fixed_name_length(row[0]));
547
mysql_free_result(res);
549
} /* process_all_tables_in_db */
553
static int fix_table_storage_name(const char *name)
555
char qbuf[100 + NAME_LEN*4];
557
if (strncmp(name, "#mysql50#", 9))
559
sprintf(qbuf, "RENAME TABLE `%s` TO `%s`", name, name + 9);
560
if (mysql_query(sock, qbuf))
562
fprintf(stderr, "Failed to %s\n", qbuf);
563
fprintf(stderr, "Error: %s\n", mysql_error(sock));
567
printf("%-50s %s\n", name, rc ? "FAILED" : "OK");
571
static int fix_database_storage_name(const char *name)
573
char qbuf[100 + NAME_LEN*4];
575
if (strncmp(name, "#mysql50#", 9))
577
sprintf(qbuf, "ALTER DATABASE `%s` UPGRADE DATA DIRECTORY NAME", name);
578
if (mysql_query(sock, qbuf))
580
fprintf(stderr, "Failed to %s\n", qbuf);
581
fprintf(stderr, "Error: %s\n", mysql_error(sock));
585
printf("%-50s %s\n", name, rc ? "FAILED" : "OK");
589
static int process_one_db(char *database)
591
if (what_to_do == DO_UPGRADE)
594
if (opt_fix_db_names && !strncmp(database,"#mysql50#", 9))
596
rc= fix_database_storage_name(database);
599
if (rc || !opt_fix_table_names)
602
return process_all_tables_in_db(database);
606
static int use_db(char *database)
608
if (mysql_get_server_version(sock) >= 50003 &&
609
!my_strcasecmp(&my_charset_latin1, database, "information_schema"))
611
if (mysql_select_db(sock, database))
613
DBerror(sock, "when selecting the database");
620
static int handle_request_for_tables(char *tables, uint length)
622
char *query, *end, options[100], message[100];
623
uint query_length= 0;
628
switch (what_to_do) {
631
if (opt_quick) end = strmov(end, " QUICK");
632
if (opt_fast) end = strmov(end, " FAST");
633
if (opt_medium_check) end = strmov(end, " MEDIUM"); /* Default */
634
if (opt_extended) end = strmov(end, " EXTENDED");
635
if (opt_check_only_changed) end = strmov(end, " CHANGED");
636
if (opt_upgrade) end = strmov(end, " FOR UPGRADE");
639
op= (opt_write_binlog) ? "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG";
640
if (opt_quick) end = strmov(end, " QUICK");
641
if (opt_extended) end = strmov(end, " EXTENDED");
642
if (opt_frm) end = strmov(end, " USE_FRM");
645
op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG";
648
op= (opt_write_binlog) ? "OPTIMIZE" : "OPTIMIZE NO_WRITE_TO_BINLOG";
651
return fix_table_storage_name(tables);
654
if (!(query =(char *) my_malloc((sizeof(char)*(length+110)), MYF(MY_WME))))
658
/* No backticks here as we added them before */
659
query_length= my_sprintf(query,
660
(query, "%s TABLE %s %s", op, tables, options));
666
ptr= strmov(strmov(query, op), " TABLE ");
667
ptr= fix_table_name(ptr, tables);
668
ptr= strxmov(ptr, " ", options, NullS);
669
query_length= (uint) (ptr - query);
671
if (mysql_real_query(sock, query, query_length))
673
sprintf(message, "when executing '%s TABLE ... %s'", op, options);
674
DBerror(sock, message);
678
my_free(query, MYF(0));
683
static void print_result()
687
char prev[NAME_LEN*2+2];
689
my_bool found_error=0;
691
res = mysql_use_result(sock);
694
for (i = 0; (row = mysql_fetch_row(res)); i++)
696
int changed = strcmp(prev, row[0]);
697
my_bool status = !strcmp(row[2], "status");
702
if there was an error with the table, we have --auto-repair set,
703
and this isn't a repair op, then add the table to the tables4repair
706
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR &&
708
insert_dynamic(&tables4repair, (uchar*) prev);
713
if (status && changed)
714
printf("%-50s %s", row[0], row[3]);
715
else if (!status && changed)
717
printf("%s\n%-9s: %s", row[0], row[2], row[3]);
718
if (strcmp(row[2],"note"))
722
printf("%-9s: %s", row[2], row[3]);
723
strmov(prev, row[0]);
726
/* add the last table to be repaired to the list */
727
if (found_error && opt_auto_repair && what_to_do != DO_REPAIR)
728
insert_dynamic(&tables4repair, (uchar*) prev);
729
mysql_free_result(res);
733
static int dbConnect(char *host, char *user, char *passwd)
735
DBUG_ENTER("dbConnect");
738
fprintf(stderr, "# Connecting to %s...\n", host ? host : "localhost");
740
mysql_init(&mysql_connection);
742
mysql_options(&mysql_connection, MYSQL_OPT_COMPRESS, NullS);
745
mysql_ssl_set(&mysql_connection, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
746
opt_ssl_capath, opt_ssl_cipher);
749
mysql_options(&mysql_connection,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
751
if (shared_memory_base_name)
752
mysql_options(&mysql_connection,MYSQL_SHARED_MEMORY_BASE_NAME,shared_memory_base_name);
754
if (!(sock = mysql_real_connect(&mysql_connection, host, user, passwd,
755
NULL, opt_mysql_port, opt_mysql_unix_port, 0)))
757
DBerror(&mysql_connection, "when trying to connect");
760
mysql_connection.reconnect= 1;
765
static void dbDisconnect(char *host)
768
fprintf(stderr, "# Disconnecting from %s...\n", host ? host : "localhost");
773
static void DBerror(MYSQL *mysql, const char *when)
775
DBUG_ENTER("DBerror");
776
my_printf_error(0,"Got error: %d: %s %s", MYF(0),
777
mysql_errno(mysql), mysql_error(mysql), when);
778
safe_exit(EX_MYSQLERR);
783
static void safe_exit(int error)
795
int main(int argc, char **argv)
799
** Check out the args
801
if (get_options(&argc, &argv))
806
if (dbConnect(current_host, current_user, opt_password))
809
if (opt_auto_repair &&
810
my_init_dynamic_array(&tables4repair, sizeof(char)*(NAME_LEN*2+2),16,64))
817
process_all_databases();
818
/* Only one database and selected table(s) */
819
else if (argc > 1 && !opt_databases)
820
process_selected_tables(*argv, (argv + 1), (argc - 1));
821
/* One or more databases, all tables */
823
process_databases(argv);
828
if (!opt_silent && tables4repair.elements)
829
puts("\nRepairing tables");
830
what_to_do = DO_REPAIR;
831
for (i = 0; i < tables4repair.elements ; i++)
833
char *name= (char*) dynamic_array_ptr(&tables4repair, i);
834
handle_request_for_tables(name, fixed_name_length(name));
838
dbDisconnect(current_host);
840
delete_dynamic(&tables4repair);
841
my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
843
my_free(shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
846
return(first_error!=0);