static my_bool not_used; /* Can't use GET_BOOL without a value pointer */
char upgrade_from_version[1024];
static my_bool opt_write_binlog;
staticvoid print_conn_args(constchar *tool_name);
#define OPT_SILENT OPT_MAX_CLIENT_OPTION
staticstruct my_option my_long_options[]=
{
{"help", '?', "Display this help message and exit.", 0, 0, 0, GET_NO_ARG,
NO_ARG, 0, 0, 0, 0, 0, 0},
{"basedir", 'b', "Not used by mysql_upgrade. Only for backward compatibility.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"character-sets-dir", 0, "Not used by mysql_upgrade. Only for backward compatibility.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
{"compress", 0, "Not used by mysql_upgrade. Only for backward compatibility.",
¬_used, ¬_used, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"datadir", 'd', "Not used by mysql_upgrade. Only for backward compatibility.", 0, 0, 0, GET_STR, REQUIRED_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.", 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", 'T', "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, "Not used by mysql_upgrade. Only for backward compatibility.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"default_auth", OPT_DEFAULT_AUTH, "Default authentication client-side plugin to use.",
&opt_default_auth, &opt_default_auth, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"check-if-upgrade-is-needed", OPT_CHECK_IF_UPGRADE_NEEDED, "Exits with status 0 if an upgrades is required, 1 otherwise.",
&opt_check_upgrade, &opt_check_upgrade, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", 'f', "Force execution of mysqlcheck even if mysql_upgrade " "has already been executed for the current version of MariaDB.",
&opt_not_used, &opt_not_used, 0 , GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"host", 'h', "Connect to host.", 0, 0, 0, GET_STR, REQUIRED_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.", &opt_password,&opt_password, 0, GET_STR, OPT_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", OPT_PLUGIN_DIR, "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) ").", 0, 0, 0, GET_STR, 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},
{"silent", OPT_SILENT, "Print less information", &opt_silent,
&opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"socket", 'S', "The socket file to use for connection.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, #include <sslopt-longopts.h>
{"tmpdir", 't', "Directory for temporary files.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"upgrade-system-tables", 's', "Only upgrade the system tables in the mysql database. Tables in other databases are not checked or touched.",
&opt_systables_only, &opt_systables_only, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"user", 'u', "User for login.", &opt_user,
&opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Display more output about the process; Using it twice will print connection argument;" "Using it 3 times will print out all CHECK, RENAME and ALTER TABLE during the check phase;" "Using it 4 times (added in MariaDB 10.0.14) will also write out all mariadb-check commands used;" "Using it 5 times will print all the mariadb commands used and their results while running mysql_fix_privilege_tables script.",
&opt_not_used, &opt_not_used, 0, GET_BOOL, NO_ARG, 1, 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},
{"version-check", 'k', "Run this program only if its \'server version\' " "matches the version of the server to which it's connecting. " "Note: the \'server version\' of the program is the version of the MariaDB " "server with which it was built/distributed.",
&opt_version_check, &opt_version_check, 0,
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
{"write-binlog", OPT_WRITE_BINLOG, "All commands including those " "issued by mysqlcheck are written to the binary log.",
&opt_write_binlog, &opt_write_binlog, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
staticconstchar *load_default_groups[]=
{ "client", /* Read settings how to connect to server */ "mysql_upgrade", /* Read special settings for mysql_upgrade */ "mariadb-upgrade", /* Read special settings for mysql_upgrade */ "client-server", /* Reads settings common between client & server */ "client-mariadb", /* Read mariadb unique client settings */ 0
};
staticvoid free_used_memory(void)
{ /* Free memory allocated by 'load_defaults' */ if (defaults_argv)
free_defaults(defaults_argv);
if (init_dynamic_string(&ds_datadir, NULL, 32, 32))
die("Out of memory");
if (run_query("show variables like 'datadir'",
&ds_datadir, FALSE) ||
extract_variable_from_show(&ds_datadir, name))
{
print_error("Reading datadir from the MariaDB server failed. Got the " "following error when executing the 'mysql' command line client",
&ds_datadir);
dynstr_free(&ds_datadir);
DBUG_RETURN(1); /* Query failed */
}
if ((info_file= my_create(upgrade_info_file, 0,
O_RDWR | O_NOFOLLOW,
MYF(0))) < 0)
{ if (opt_force >= 2)
{
fprintf(stdout, create_error_message, "", upgrade_info_file, errno,
my_strerror(errbuff, sizeof(errbuff)-1, errno));
fprintf(stdout, "--force --force used, continuing without using the %s file.\n" "Note that this means that there is no protection against " "concurrent mysql_upgrade executions and next mysql_upgrade run " "will do a full upgrade again!\n",
upgrade_info_file); return;
}
fprintf(stdout, create_error_message, "FATAL ERROR: ",
upgrade_info_file, errno,
my_strerror(errbuff, sizeof(errbuff)-1, errno)); if (errno == EACCES)
{
fprintf(stderr, "Note that mysql_upgrade should be run as the same user as the " "MariaDB server binary, normally 'mysql' or 'root'.\n" "Alternatively you can use mysql_upgrade --force --force. " "Please check the documentation if you decide to use the force " "option!\n");
}
fflush(stderr);
die(0);
} if (my_lock(info_file, F_WRLCK, 0, 1, MYF(0)))
{
die("Could not exclusively lock on file '%s'. Error %d: %s\n",
upgrade_info_file, my_errno,
my_strerror(errbuff, sizeof(errbuff)-1, my_errno));
}
}
(void) my_seek(info_file, 0, SEEK_SET, MYF(0)); /* We have -3 here to make calc_server_version() safe */
length= my_read(info_file, (uchar*) upgrade_from_version, sizeof(upgrade_from_version)-3,
MYF(MY_WME));
if (!length)
{ if (opt_verbose)
verbose("Empty or non existent %s. Assuming mysql_upgrade has to be run!",
upgrade_info_file); return1;
}
/* Remove possible \ŋ that may end in output */ if ((pos= strchr(upgrade_from_version, '\n')))
*pos= 0;
if (faulty_server_versions(upgrade_from_version))
{ if (opt_verbose)
verbose("Upgrading from version %s requires mysql_upgrade to be run!",
upgrade_from_version); return2;
}
s= strchr(version, '.');
s= strchr(s + 1, '.');
if (strncmp(upgrade_from_version, version, (size_t)(s - version + 1)))
{ if (calc_server_version(upgrade_from_version) <= MYSQL_VERSION_ID)
{
verbose("Major version upgrade detected from %s to %s. Check required!",
upgrade_from_version, version); return3;
}
die("Version mismatch (%s -> %s): Trying to downgrade from a higher to " "lower version is not supported!",
upgrade_from_version, version);
} if (!silent)
{ if (strcmp(upgrade_from_version, version))
verbose("This installation of MariaDB is already upgraded to %s.\n" "There is no need to run mariadb-upgrade again for %s, because " "they're both %.*s.",
upgrade_from_version, version, (int)(s - version), version); else
verbose("This installation of MariaDB is already upgraded to %s.\n" "There is no need to run mariadb-upgrade again.", version); if (!opt_check_upgrade)
verbose("You can use --force if you still want to run mariadb-upgrade");
} return0;
}
staticvoid finish_mariadb_upgrade_info_file(void)
{ if (info_file < 0) return;
/* Checkiftheupgrade_info_filewasproperlycreated/updated It'snotafatalerror->justprintamessageifitfails
*/ if (upgrade_already_done(1))
fprintf(stderr, "Could not write to the upgrade info file '%s' in " "the MariaDB Servers datadir, errno: %d\n",
upgrade_info_file, errno);
if (init_dynamic_string(&ds_events_struct, NULL, 2048, 2048))
die("Out of memory");
if (run_query("show create table mysql.user", &ds_events_struct, FALSE) ||
strstr(ds_events_struct.str, "default_role") != NULL)
ret= FALSE; else
verbose("Upgrading from a version before MariaDB-10.1");
if (run_query(buf, NULL, TRUE))
fprintf(stderr, "... can't %s\n", buf);
line=next;
next=get_line(line);
} while (*line);
}
dynstr_free(&ds_result); return0;
}
staticint check_slave_repositories(void)
{
DYNAMIC_STRING ds_result; int row_count= 0; int error= 0; constchar *query = "SELECT COUNT(*) AS c1 FROM mysql.slave_master_info";
if (init_dynamic_string(&ds_result, "", 512, 512))
die("Out of memory");
run_query(query, &ds_result, TRUE);
if (ds_result.length)
{
row_count= atoi((char *)ds_result.str); if (row_count)
{
fprintf(stderr,"Slave info repository compatibility check:" " Found data in `mysql`.`slave_master_info` table.\n");
fprintf(stderr,"Warning: Content of `mysql`.`slave_master_info` table" " will be ignored as MariaDB supports file based info " "repository.\n");
error= 1;
}
}
dynstr_free(&ds_result);
query = "SELECT COUNT(*) AS c1 FROM mysql.slave_relay_log_info";
if (init_dynamic_string(&ds_result, "", 512, 512))
die("Out of memory");
run_query(query, &ds_result, TRUE);
if (ds_result.length)
{
row_count= atoi((char *)ds_result.str); if (row_count)
{
fprintf(stderr, "Slave info repository compatibility check:" " Found data in `mysql`.`slave_relay_log_info` table.\n");
fprintf(stderr, "Warning: Content of `mysql`.`slave_relay_log_info` " "table will be ignored as MariaDB supports file based " "repository.\n");
error= 1;
}
}
dynstr_free(&ds_result); if (error)
{
fprintf(stderr,"Slave server may not possess the correct replication " "metadata.\n");
fprintf(stderr, "Execution of CHANGE MASTER as per " "`mysql`.`slave_master_info` and `mysql`.`slave_relay_log_info` " "table content is recommended.\n");
} return0;
}
if (init_dynamic_string(&ds_version, NULL, NAME_CHAR_LEN, NAME_CHAR_LEN))
die("Out of memory");
if (run_query("show variables like 'version'",
&ds_version, FALSE) ||
extract_variable_from_show(&ds_version, version_str))
{
print_error("Version check failed. Got the following error when calling " "the 'mysql' command line client", &ds_version);
dynstr_free(&ds_version); return1; /* Query failed */
}
dynstr_free(&ds_version);
if (calc_server_version((char *) version_str) != MYSQL_VERSION_ID)
{
fprintf(stderr, "Error: Server version (%s)\n" "does not match the version of the server (%s)\n" "with which this program was built/distributed. You can\n" "use --skip-version-check to skip this check.\n",
version_str, MYSQL_SERVER_VERSION); return1;
} return0;
}
int main(int argc, char **argv)
{ char self_name[FN_REFLEN + 1];
MY_INIT(argv[0]);
DBUG_PROCESS(argv[0]);
load_defaults_or_exit("my", load_default_groups, &argc, &argv);
defaults_argv= argv; /* Must be freed by 'free_defaults' */
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.