staticstruct my_option my_long_options[] =
{
{"all-databases", 'A', "Check all the databases. This is the same as --databases with all databases selected.",
&opt_alldbs, &opt_alldbs, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"analyze", 'a', "Analyze given tables.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"all-in-1", '1', "Instead of issuing one query for each table, use one query per database, naming all tables in the database in a comma-separated list.",
&opt_all_in_1, &opt_all_in_1, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"auto-repair", 0, "If a checked table is corrupted, automatically fix it. Repairing will be done after all tables have been checked, if corrupted ones were found.",
&opt_auto_repair, &opt_auto_repair, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"character-sets-dir", 0, "Directory for character set files.", (char**) &charsets_dir,
(char**) &charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"check", 'c', "Check table for errors.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"check-only-changed", 'C', "Check only tables that have changed since last check or haven't been closed properly.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"check-upgrade", 'g', "Check tables for version-dependent changes. May be used with --auto-repair to correct tables requiring version-dependent updates.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"compress", 0, "Use compression in server/client protocol.",
&opt_compress, &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"databases", 'B', "Check several databases. Note the difference in usage; in this case no tables are given. All name arguments are regarded as database names.",
&opt_databases, &opt_databases, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifdef DBUG_OFF
{"debug", '#', "This is a non-debug version. Catch this and exit.", 0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0}, #else
{"debug", '#', "Output debug log. Often this is 'd:t:o,filename'.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"debug-check", 0, "Check memory and open file usage at exit.",
&debug_check_flag, &debug_check_flag, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"debug-info", 0, "Print some debug info at exit.",
&debug_info_flag, &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"default-character-set", 0, "Set the default character set.", &default_charset,
&default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"default_auth", 0, "Default authentication client-side plugin to use.",
&opt_default_auth, &opt_default_auth, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"fast",'F', "Check only tables that haven't been closed properly.",
&opt_fast, &opt_fast, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"fix-db-names", OPT_FIX_DB_NAMES, "Fix database names.",
&opt_fix_db_names, &opt_fix_db_names, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"fix-table-names", OPT_FIX_TABLE_NAMES, "Fix table names.",
&opt_fix_table_names, &opt_fix_table_names, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", 'f', "Continue even if we get an SQL error.",
&ignore_errors, &ignore_errors, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"extended", 'e', "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.",
&opt_extended, &opt_extended, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"flush", 0, "Flush each table after check. This is useful if you don't want to have the checked tables take up space in the caches after the check",
&opt_flush_tables, &opt_flush_tables, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0 },
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"host",'h', "Connect to host. Defaults in the following order: " "$MARIADB_HOST, and then localhost",
¤t_host, ¤t_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"medium-check", 'm', "Faster than extended-check, but only finds 99.99 percent of all errors. Should be good enough for most cases.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"write-binlog", 0, "Log ANALYZE, OPTIMIZE and REPAIR TABLE commands. Use --skip-write-binlog " "when commands should not be sent to replication slaves.",
&opt_write_binlog, &opt_write_binlog, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"optimize", 'o', "Optimize table.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p', "Password to use when connecting to server. If password is not given, it's solicited on the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"persistent", 'Z', "When using ANALYZE TABLE use the PERSISTENT FOR ALL option.",
&opt_persistent_all, &opt_persistent_all, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifdef _WIN32
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"plugin_dir", 0, "Directory for client-side plugins.",
&opt_plugin_dir, &opt_plugin_dir, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"port", 'P', "Port number to use for connection or 0 for default to, in " "order of preference, my.cnf, $MYSQL_TCP_PORT, " #if MYSQL_PORT_DEFAULT == 0 "/etc/services, " #endif "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
&opt_mysql_port, &opt_mysql_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"protocol", OPT_MYSQL_PROTOCOL, "The protocol to use for connection (tcp, socket, pipe).", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"quick", 'q', "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.",
&opt_quick, &opt_quick, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"repair", 'r', "Can fix almost anything except unique keys that aren't unique.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"silent", 's', "Print only error messages.", &opt_silent,
&opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"skip_database", 0, "Don't process the database specified as argument",
&opt_skip_database, &opt_skip_database, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"socket", 'S', "The socket file to use for connection.",
&opt_mysql_unix_port, &opt_mysql_unix_port, 0, GET_STR,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #include <sslopt-longopts.h>
{"tables", OPT_TABLES, "Overrides option --databases (-B).", 0, 0, 0,
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"use-frm", 0, "When used with REPAIR, get table structure from .frm file, so the table can be repaired even if .MYI header is corrupted.",
&opt_frm, &opt_frm, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, #ifndef DONT_ALLOW_USER_CHANGE
{"user", 'u', "User for login if not current user.", ¤t_user,
¤t_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #endif
{"verbose", 'v', "Print info about the various stages; Using it 3 times will print out all CHECK, RENAME and ALTER TABLE during the check phase.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
{"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"process-views", 0, "Perform the requested operation (check or repair) on views. " "One of: NO, YES (correct the checksum, if necessary, add the " "mariadb-version field), UPGRADE (run from mariadb-upgrade), " "UPGRADE_FROM_MYSQL (same as YES and toggle the algorithm " "MERGE<->TEMPTABLE.", &opt_do_views, &opt_do_views,
&do_views_typelib, GET_ENUM, OPT_ARG, 0, 0, 0, 0, 0, 0},
{"process-tables", 0, "Perform the requested operation on tables.",
&opt_do_tables, &opt_do_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
staticvoid usage(void)
{
DBUG_ENTER("usage");
print_version();
puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000"));
puts("This program can be used to CHECK (-c, -m, -C), REPAIR (-r), ANALYZE (-a),");
puts("or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be");
puts("used at the same time. Not all options are supported by all storage engines.");
puts("The options -c, -r, -a, and -o are exclusive to each other, which");
puts("means that the last option will be used, if several was specified.\n");
puts("The option -c (--check) will be used by default, if none was specified.");
puts("You can change the default behavior by making a symbolic link, or");
puts("copying this file somewhere with another name, the alternatives are:");
puts("mysqlrepair: The default option will be -r");
puts("mysqlanalyze: The default option will be -a");
puts("mysqloptimize: The default option will be -o\n");
printf("Usage: %s [OPTIONS] database [tables]\n", my_progname);
printf("OR %s [OPTIONS] --databases DB1 [DB2 DB3...]\n",
my_progname);
puts("Please consult the MariaDB Documentation at");
puts("https://mariadb.com/docs/server/clients-and-utilities/legacy-clients-and-utilities/mysqlcheck for latest information about");
puts("this program.");
print_defaults("my", load_default_groups);
puts("");
my_print_help(my_long_options);
my_print_variables(my_long_options);
DBUG_VOID_RETURN;
} /* usage */
switch(opt->id) { case'a':
what_to_do = DO_ANALYZE; break; case'c':
what_to_do = DO_CHECK; break; case'C':
what_to_do = DO_CHECK;
opt_check_only_changed = 1; break; case'I': /* Fall through */ case'?':
usage(); exit(0); case'm':
what_to_do = DO_CHECK;
opt_medium_check = 1; break; case'o':
what_to_do = DO_OPTIMIZE; break; case OPT_FIX_DB_NAMES:
what_to_do= DO_FIX_NAMES;
opt_databases= 1; break; case OPT_FIX_TABLE_NAMES:
what_to_do= DO_FIX_NAMES; break; case'p': if (argument == disabled_my_option)
argument= (char*) ""; /* Don't require password */ if (argument)
{ /* Oneshouldnotreallychangetheargument,butwemakean exceptionforpasswords
*/ char *start= (char*) argument;
my_free(opt_password);
opt_password = my_strdup(PSI_NOT_INSTRUMENTED, argument, MYF(MY_FAE)); while (*argument)
*(char*) argument++= 'x'; /* Destroy argument */ if (*start)
start[1] = 0; /* Cut length of argument */
tty_password= 0;
} else
tty_password = 1; break; case'r':
what_to_do = DO_REPAIR; break; case'g':
what_to_do= DO_CHECK;
opt_upgrade= 1; break; case'W': #ifdef _WIN32
opt_protocol = MYSQL_PROTOCOL_PIPE; #endif break; case'#':
DBUG_PUSH(argument ? argument : "d:t:o");
debug_check_flag= 1; break; #include <sslopt-case.h> case OPT_TABLES:
opt_databases = 0; break; case'v':
verbose++; break; case'V':
print_version(); exit(0); break; case OPT_MYSQL_PROTOCOL: if ((opt_protocol= find_type_with_warning(argument, &sql_protocol_typelib,
opt->name)) <= 0)
{
sf_leaking_memory= 1; /* no memory leak reports here */ exit(1);
} break; case'P': if (filename[0] == '\0')
{ /* Port given on command line, switch protocol to use TCP */
opt_protocol= MYSQL_PROTOCOL_TCP;
} break; case'S': if (filename[0] == '\0')
{ /* Socketgivenoncommandline,switchprotocoltouseSOCKETSt ExceptonWindowsif'protocol=pipe'hasbeenprovidedin theconfigfileorcommandline.
*/ if (opt_protocol != MYSQL_PROTOCOL_PIPE)
{
opt_protocol= MYSQL_PROTOCOL_SOCKET;
}
} break;
}
if (orig_what_to_do && (what_to_do != orig_what_to_do))
{
fprintf(stderr, "Error: %s doesn't support multiple contradicting commands.\n",
my_progname);
DBUG_RETURN(1);
}
DBUG_RETURN(0);
}
staticint get_options(int *argc, char ***argv)
{ int ho_error;
DBUG_ENTER("get_options");
if (current_host == NULL)
current_host= getenv("MARIADB_HOST");
if (*argc == 1)
{
usage(); exit(0);
}
if ((ho_error=handle_options(argc, argv, my_long_options, get_one_option))) exit(ho_error);
if (what_to_do == DO_REPAIR && !opt_do_views && !opt_do_tables)
{
fprintf(stderr, "Error: Nothing to repair when both " "--process-tables=NO and --process-views=NO\n"); exit(1);
} if (!what_to_do)
{
size_t pnlen= strlen(my_progname);
if (opt_do_views && what_to_do != DO_REPAIR && what_to_do != DO_CHECK)
{
fprintf(stderr, "Error: %s doesn't support %s for views.\n",
my_progname, operation_name[what_to_do]); exit(1);
}
/* Ifthere'sno--default-character-setoptiongivenwith --fix-table-nameor--fix-db-namesetthedefaultcharactersetto"utf8".
*/ if (!default_charset)
{ if (opt_fix_db_names || opt_fix_table_names)
default_charset= (char*) "utf8"; else
default_charset= (char*) MYSQL_AUTODETECT_CHARSET_NAME;
} if (!strcmp(default_charset, MYSQL_AUTODETECT_CHARSET_NAME))
default_charset= (char *)my_default_csname();
if (!get_charset_by_csname(default_charset, MY_CS_PRIMARY,
MYF(MY_UTF8_IS_UTF8MB3 | MY_WME)))
{
printf("Unsupported character set: %s\n", default_charset);
DBUG_RETURN(1);
}
my_set_console_cp(default_charset); if (*argc > 0 && opt_alldbs)
{
printf("You should give only options, no arguments at all, with option\n");
printf("--all-databases. Please see %s --help for more information.\n",
my_progname);
DBUG_RETURN(1);
} if (*argc < 1 && !opt_alldbs)
{
printf("You forgot to give the arguments! Please see %s --help\n",
my_progname);
printf("for more information.\n");
DBUG_RETURN(1);
} if (tty_password)
opt_password = my_get_tty_password(NullS); if (debug_info_flag)
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO; if (debug_check_flag)
my_end_arg= MY_CHECK_ERROR;
DBUG_RETURN((0));
} /* get_options */
staticint process_all_databases()
{
MYSQL_ROW row;
MYSQL_RES *tableres; int result = 0;
DBUG_ENTER("process_all_databases");
if (mysql_query(sock, "SHOW DATABASES") ||
!(tableres = mysql_store_result(sock)))
{
my_printf_error(0, "Error: Couldn't execute 'SHOW DATABASES': %s",
MYF(0), mysql_error(sock));
DBUG_RETURN(1);
} if (verbose)
printf("Processing databases\n"); while ((row = mysql_fetch_row(tableres)))
{ if (process_one_db(row[0]))
result = 1;
}
mysql_free_result(tableres);
DBUG_RETURN(result);
} /* process_all_databases */
staticint process_databases(char **db_names)
{ int result = 0;
DBUG_ENTER("process_databases");
if (verbose)
printf("Processing databases\n"); for ( ; *db_names ; db_names++)
{ if (process_one_db(*db_names))
result = 1;
}
DBUG_RETURN(result);
} /* process_databases */
/* returns: -1 for error, 1 for view, 0 for table */ staticint is_view(constchar *table)
{ char query[1024];
MYSQL_RES *res;
MYSQL_FIELD *field; int view;
DBUG_ENTER("is_view");
staticint process_selected_tables(char *db, char **table_names, int tables)
{ int view; char *table;
size_t table_len;
DBUG_ENTER("process_selected_tables");
if (use_db(db))
DBUG_RETURN(1); if (opt_all_in_1 && what_to_do != DO_FIX_NAMES)
{ /* Weneedtablelistinform`a`,`b`,`c` that'swhyweneed2morecharsaddedtotoeachtablename spaceisformorereadableoutputinlogsandincaseoferror
*/ char *table_names_comma_sep, *end;
size_t tot_length= 0; int i= 0;
if (opt_do_tables && opt_do_views)
{
fprintf(stderr, "Error: %s cannot process both tables and views " "in one command (--process-tables=YES " "--process-views=YES --all-in-1).\n",
my_progname);
DBUG_RETURN(1);
}
for (i = 0; i < tables; i++)
tot_length+= fixed_name_length(*(table_names + i)) + 2;
if (mysql_get_server_version(sock) >= FIRST_INFORMATION_SCHEMA_VERSION &&
!cmp_database(database, INFORMATION_SCHEMA_DB_NAME))
DBUG_RETURN(1); if (mysql_get_server_version(sock) >= FIRST_PERFORMANCE_SCHEMA_VERSION &&
!cmp_database(database, PERFORMANCE_SCHEMA_DB_NAME))
DBUG_RETURN(1); if (mysql_select_db(sock, database))
{
DBerror(sock, "when selecting the database");
DBUG_RETURN(1);
}
DBUG_RETURN(0);
} /* use_db */
/* Do not send commands to replication slaves. */ staticint disable_binlog()
{
mysql_query(sock, "SET WSREP_ON=0"); /* ignore the error, if any */ return run_query("SET SQL_LOG_BIN=0", 0);
}
/* Ok as mysqlcheck is not multi threaded */
PRAGMA_DISABLE_CHECK_STACK_FRAME
options[0] = 0;
tab_view= view ? " VIEW " : " TABLE ";
end = options; switch (what_to_do) { case DO_CHECK:
op = "CHECK"; if (view)
{ if (opt_fast || opt_check_only_changed)
DBUG_RETURN(0);
} else
{ if (opt_quick) end = strmov(end, " QUICK"); if (opt_fast) end = strmov(end, " FAST"); if (opt_extended) end = strmov(end, " EXTENDED"); if (opt_medium_check) end = strmov(end, " MEDIUM"); /* Default */ if (opt_check_only_changed) end = strmov(end, " CHANGED");
} if (opt_upgrade) end = strmov(end, " FOR UPGRADE"); break; case DO_REPAIR:
op= opt_write_binlog ? "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG"; if (view)
{ if (opt_do_views == DO_VIEWS_FROM_MYSQL)
end = strmov(end, " FROM MYSQL"); elseif (opt_do_views == DO_UPGRADE)
end = strmov(end, " FOR UPGRADE");
} else
{ if (opt_quick) end = strmov(end, " QUICK"); if (opt_extended) end = strmov(end, " EXTENDED"); if (opt_frm) end = strmov(end, " USE_FRM");
} break; case DO_ANALYZE: if (view)
{
printf("%-50s %s\n", tables, "Can't run analyze on a view");
DBUG_RETURN(1);
}
DBUG_ASSERT(!view);
op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG"; if (opt_persistent_all) end = strmov(end, " PERSISTENT FOR ALL"); break; case DO_OPTIMIZE: if (view)
{
printf("%-50s %s\n", tables, "Can't run optimize on a view");
DBUG_RETURN(1);
}
op= (opt_write_binlog) ? "OPTIMIZE" : "OPTIMIZE NO_WRITE_TO_BINLOG"; break; case DO_FIX_NAMES: if (view)
{
printf("%-50s %s\n", tables, "Can't run fix names on a view");
DBUG_RETURN(1);
}
DBUG_RETURN(fix_table_storage_name(tables));
}
if (!(query =(char *) my_malloc(PSI_NOT_INSTRUMENTED, query_size, MYF(MY_WME))))
DBUG_RETURN(1); if (dont_quote)
{
DBUG_ASSERT(op);
DBUG_ASSERT(strlen(op)+strlen(tables)+strlen(options)+8+1 <= query_size);
/* No backticks here as we added them before */
query_length= my_snprintf(query, query_size, "%s%s%s %s", op,
tab_view, tables, options);
} else
{
query_length= my_snprintf(query, query_size, "%s%s%sQ %s",
op, tab_view, tables, options);
} if (verbose >= 3)
puts(query); if (mysql_real_query(sock, query, (ulong)query_length))
{
my_snprintf(message, sizeof(message), "when executing '%s%s... %s'",
op, tab_view, options);
DBerror(sock, message);
my_free(query);
DBUG_RETURN(1);
}
print_result(); if (opt_flush_tables)
{
query_length= my_snprintf(query, query_size, "FLUSH TABLES %sQ", tables); if (mysql_real_query(sock, query, (ulong)query_length))
{
DBerror(sock, query);
my_free(query);
DBUG_RETURN(1);
}
}
my_free(query);
DBUG_RETURN(0);
}
if (opt_alldbs)
process_all_databases(); /* Only one database and selected table(s) */ elseif (argc > 1 && !opt_databases)
process_selected_tables(*argv, (argv + 1), (argc - 1)); /* One or more databases, all tables */ else
process_databases(argv); if (opt_auto_repair)
{
size_t i;
if (!opt_silent && (tables4repair.elements || tables4rebuild.elements))
puts("\nRepairing tables");
what_to_do = DO_REPAIR; for (i = 0; i < tables4repair.elements ; i++)
{ char *name= (char*) dynamic_array_ptr(&tables4repair, i);
handle_request_for_tables(name, fixed_name_length(name), FALSE, TRUE);
} for (i = 0; i < tables4rebuild.elements ; i++)
rebuild_table((char*) dynamic_array_ptr(&tables4rebuild, i)); for (i = 0; i < alter_table_cmds.elements ; i++)
run_query((char*) dynamic_array_ptr(&alter_table_cmds, i), 1); if (!opt_silent && views4repair.elements)
puts("\nRepairing views"); for (i = 0; i < views4repair.elements ; i++)
{ char *name= (char*) dynamic_array_ptr(&views4repair, i);
handle_request_for_tables(name, fixed_name_length(name), TRUE, TRUE);
}
}
ret= MY_TEST(first_error);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.