2011-06-30 17:31:31 +02:00
|
|
|
/*
|
2013-07-16 19:09:54 +02:00
|
|
|
Copyright (c) 2006, 2013, Oracle and/or its affiliates.
|
2024-05-04 17:05:29 +02:00
|
|
|
Copyright (c) 2010, 2024, MariaDB
|
2006-04-28 06:07:25 +02:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2006-04-28 06:07:25 +02:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
2019-05-11 20:29:06 +02:00
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA
|
2011-06-30 17:31:31 +02:00
|
|
|
*/
|
2006-04-28 06:07:25 +02:00
|
|
|
|
|
|
|
#include "client_priv.h"
|
2006-11-08 03:45:50 +01:00
|
|
|
#include <sslopt-vars.h>
|
2022-12-12 04:20:08 +01:00
|
|
|
#include <../scripts/mariadb_fix_privilege_tables_sql.c>
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2023-06-05 09:42:04 +02:00
|
|
|
#define VER "2.1"
|
2022-12-11 00:11:43 +01:00
|
|
|
#include <welcome_copyright_notice.h> /* ORACLE_WELCOME_COPYRIGHT_NOTICE */
|
2007-08-01 21:59:05 +02:00
|
|
|
|
2007-04-19 21:30:46 +02:00
|
|
|
#ifdef HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WEXITSTATUS
|
2021-06-06 13:21:03 +02:00
|
|
|
# ifdef _WIN32
|
2007-04-19 21:30:46 +02:00
|
|
|
# define WEXITSTATUS(stat_val) (stat_val)
|
|
|
|
# else
|
|
|
|
# define WEXITSTATUS(stat_val) ((unsigned)(stat_val) >> 8)
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2015-05-04 22:00:24 +02:00
|
|
|
static int phase = 0;
|
2022-01-04 19:09:40 +01:00
|
|
|
static int info_file= -1;
|
2023-06-05 09:42:04 +02:00
|
|
|
static const int phases_total = 8;
|
2007-04-18 13:21:39 +02:00
|
|
|
static char mysql_path[FN_REFLEN];
|
|
|
|
static char mysqlcheck_path[FN_REFLEN];
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
static my_bool debug_info_flag, debug_check_flag,
|
2013-03-21 18:21:40 +01:00
|
|
|
opt_systables_only, opt_version_check;
|
2022-01-04 19:09:40 +01:00
|
|
|
static my_bool opt_not_used, opt_silent, opt_check_upgrade;
|
|
|
|
static uint opt_force, opt_verbose;
|
2011-04-25 17:22:25 +02:00
|
|
|
static uint my_end_arg= 0;
|
2007-04-18 13:21:39 +02:00
|
|
|
static char *opt_user= (char*)"root";
|
|
|
|
|
2015-05-04 22:00:24 +02:00
|
|
|
static my_bool upgrade_from_mysql;
|
|
|
|
|
2007-04-19 21:30:46 +02:00
|
|
|
static DYNAMIC_STRING ds_args;
|
2009-05-27 10:24:25 +02:00
|
|
|
static DYNAMIC_STRING conn_args;
|
2021-01-20 21:59:51 +01:00
|
|
|
static DYNAMIC_STRING ds_plugin_data_types;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
static char *opt_password= 0;
|
2011-01-16 04:59:05 +01:00
|
|
|
static char *opt_plugin_dir= 0, *opt_default_auth= 0;
|
|
|
|
|
2015-12-08 10:16:41 +01:00
|
|
|
static char *cnf_file_path= 0, defaults_file[FN_REFLEN + 32];
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static my_bool tty_password= 0;
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2010-03-09 10:18:46 +01:00
|
|
|
static char opt_tmpdir[FN_REFLEN] = "";
|
2008-05-02 14:41:19 +02:00
|
|
|
|
2006-11-08 03:45:50 +01:00
|
|
|
#ifndef DBUG_OFF
|
2020-03-31 13:10:45 +02:00
|
|
|
static char *default_dbug_option= (char*) "d:t:O,/tmp/mariadb-upgrade.trace";
|
2006-11-08 03:45:50 +01:00
|
|
|
#endif
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-02-28 21:05:39 +01:00
|
|
|
static char **defaults_argv;
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static my_bool not_used; /* Can't use GET_BOOL without a value pointer */
|
|
|
|
|
2021-09-06 17:03:11 +02:00
|
|
|
char upgrade_from_version[1024];
|
2017-03-04 17:17:00 +01:00
|
|
|
|
2009-09-28 08:24:19 +02:00
|
|
|
static my_bool opt_write_binlog;
|
|
|
|
|
2023-03-06 18:32:03 +01:00
|
|
|
static void print_conn_args(const char *tool_name);
|
|
|
|
|
2011-04-25 17:22:25 +02:00
|
|
|
#define OPT_SILENT OPT_MAX_CLIENT_OPTION
|
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
static struct 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},
|
2010-09-06 01:15:34 +02:00
|
|
|
{"basedir", 'b',
|
|
|
|
"Not used by mysql_upgrade. Only for backward compatibility.",
|
2007-04-18 13:21:39 +02:00
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2024-05-04 17:05:29 +02:00
|
|
|
{"character-sets-dir", 0,
|
2010-09-06 01:15:34 +02:00
|
|
|
"Not used by mysql_upgrade. Only for backward compatibility.",
|
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0 },
|
2024-05-04 17:05:29 +02:00
|
|
|
{"compress", 0,
|
2010-09-06 01:15:34 +02:00
|
|
|
"Not used by mysql_upgrade. Only for backward compatibility.",
|
Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.
Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.
As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.
The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.
client/mysql.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysql_upgrade.c:
Remove now-unnecessary casts.
client/mysqladmin.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysqlbinlog.cc:
Remove now-unnecessary casts.
client/mysqlcheck.c:
Remove now-unnecessary casts.
client/mysqldump.c:
Remove now-unnecessary casts.
client/mysqlimport.c:
Remove now-unnecessary casts.
client/mysqlshow.c:
Remove now-unnecessary casts.
client/mysqlslap.c:
Remove now-unnecessary casts.
client/mysqltest.cc:
Remove now-unnecessary casts.
extra/comp_err.c:
Remove now-unnecessary casts.
extra/my_print_defaults.c:
Remove now-unnecessary casts.
Break up large strings.
extra/mysql_waitpid.c:
Remove now-unnecessary casts.
extra/perror.c:
Remove now-unnecessary casts.
extra/resolve_stack_dump.c:
Remove now-unnecessary casts.
extra/resolveip.c:
Remove now-unnecessary casts.
include/my_getopt.h:
Use a void pointer type as the opaque type to avoid problems with type
incompatibility -- GCC issues warnings when the type name is not type
compatible with a operand. As a side bonus, a explicit cast won't be
necessary anymore.
include/sslopt-longopts.h:
Remove now-unnecessary casts.
Break up large strings.
mysys/my_getopt.c:
Update opaque type and introduce a type definition for the
argument to my_getopt_register_get_addr.
server-tools/instance-manager/options.cc:
Remove now-unnecessary casts.
sql/mysqld.cc:
Remove now-unnecessary casts.
Break up large strings.
Update mysql_getopt_value prototype (the old prototype
was different from the definition anyway).
sql/sql_plugin.cc:
The type of a pointer to a function must be compatible with the
pointed-to function type, otherwise the behavior is undefined.
sql/table.cc:
The variable buf pointer to pointer to pointer to constant char
could improperly alias a incompatible type in call to fix_type_
pointers. Since this was actually dead code, it is simply removed.
sql/unireg.cc:
Remove call to get_form_pos. The code creates a new FRM file which
is always truncated and writes the form position as 0. Hence, no
need to retrieve it, we now for sure it is 0.
storage/archive/archive_reader.c:
Remove now-unnecessary casts.
storage/myisam/ft_nlq_search.c:
Read weight directly from the buffer.
storage/myisam/fulltext.h:
Add explanation about the type duality of a key buffer.
Add accessor macro to retrieve a FT float value.
storage/myisam/mi_test1.c:
Remove now-unnecessary casts.
storage/myisam/myisam_ftdump.c:
Read weight directly from the buffer.
storage/myisam/myisamchk.c:
Remove now-unnecessary casts.
storage/myisam/myisamlog.c:
A pointer to char was used to alias a pointer to pointer to
unsigned char, thus violating strict aliasing rules.
storage/myisam/myisampack.c:
Remove now-unnecessary casts.
strings/decimal.c:
Remove aliasing violation, printing the value is enough for
debugging purposes.
tests/mysql_client_test.c:
Remove now-unnecessary casts.
2010-06-10 22:16:43 +02:00
|
|
|
¬_used, ¬_used, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2007-04-18 13:21:39 +02:00
|
|
|
{"datadir", 'd',
|
2010-02-04 13:39:42 +01:00
|
|
|
"Not used by mysql_upgrade. Only for backward compatibility.",
|
2007-04-18 13:21:39 +02:00
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
#ifdef DBUG_OFF
|
2010-02-04 13:39:42 +01:00
|
|
|
{"debug", '#', "This is a non-debug version. Catch this and exit.",
|
2006-04-28 06:07:25 +02:00
|
|
|
0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
#else
|
2022-01-04 19:09:40 +01:00
|
|
|
{"debug", '#', "Output debug log.",
|
|
|
|
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
#endif
|
2024-05-04 17:05:29 +02:00
|
|
|
{"debug-check", 0, "Check memory and open file usage at exit.",
|
2010-09-06 01:15:34 +02:00
|
|
|
&debug_check_flag, &debug_check_flag,
|
|
|
|
0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.
Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.
As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.
The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.
client/mysql.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysql_upgrade.c:
Remove now-unnecessary casts.
client/mysqladmin.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysqlbinlog.cc:
Remove now-unnecessary casts.
client/mysqlcheck.c:
Remove now-unnecessary casts.
client/mysqldump.c:
Remove now-unnecessary casts.
client/mysqlimport.c:
Remove now-unnecessary casts.
client/mysqlshow.c:
Remove now-unnecessary casts.
client/mysqlslap.c:
Remove now-unnecessary casts.
client/mysqltest.cc:
Remove now-unnecessary casts.
extra/comp_err.c:
Remove now-unnecessary casts.
extra/my_print_defaults.c:
Remove now-unnecessary casts.
Break up large strings.
extra/mysql_waitpid.c:
Remove now-unnecessary casts.
extra/perror.c:
Remove now-unnecessary casts.
extra/resolve_stack_dump.c:
Remove now-unnecessary casts.
extra/resolveip.c:
Remove now-unnecessary casts.
include/my_getopt.h:
Use a void pointer type as the opaque type to avoid problems with type
incompatibility -- GCC issues warnings when the type name is not type
compatible with a operand. As a side bonus, a explicit cast won't be
necessary anymore.
include/sslopt-longopts.h:
Remove now-unnecessary casts.
Break up large strings.
mysys/my_getopt.c:
Update opaque type and introduce a type definition for the
argument to my_getopt_register_get_addr.
server-tools/instance-manager/options.cc:
Remove now-unnecessary casts.
sql/mysqld.cc:
Remove now-unnecessary casts.
Break up large strings.
Update mysql_getopt_value prototype (the old prototype
was different from the definition anyway).
sql/sql_plugin.cc:
The type of a pointer to a function must be compatible with the
pointed-to function type, otherwise the behavior is undefined.
sql/table.cc:
The variable buf pointer to pointer to pointer to constant char
could improperly alias a incompatible type in call to fix_type_
pointers. Since this was actually dead code, it is simply removed.
sql/unireg.cc:
Remove call to get_form_pos. The code creates a new FRM file which
is always truncated and writes the form position as 0. Hence, no
need to retrieve it, we now for sure it is 0.
storage/archive/archive_reader.c:
Remove now-unnecessary casts.
storage/myisam/ft_nlq_search.c:
Read weight directly from the buffer.
storage/myisam/fulltext.h:
Add explanation about the type duality of a key buffer.
Add accessor macro to retrieve a FT float value.
storage/myisam/mi_test1.c:
Remove now-unnecessary casts.
storage/myisam/myisam_ftdump.c:
Read weight directly from the buffer.
storage/myisam/myisamchk.c:
Remove now-unnecessary casts.
storage/myisam/myisamlog.c:
A pointer to char was used to alias a pointer to pointer to
unsigned char, thus violating strict aliasing rules.
storage/myisam/myisampack.c:
Remove now-unnecessary casts.
strings/decimal.c:
Remove aliasing violation, printing the value is enough for
debugging purposes.
tests/mysql_client_test.c:
Remove now-unnecessary casts.
2010-06-10 22:16:43 +02:00
|
|
|
{"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},
|
2024-05-04 17:05:29 +02:00
|
|
|
{"default-character-set", 0,
|
2010-09-06 01:15:34 +02:00
|
|
|
"Not used by mysql_upgrade. Only for backward compatibility.",
|
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2011-01-16 04:59:05 +01:00
|
|
|
{"default_auth", OPT_DEFAULT_AUTH,
|
|
|
|
"Default authentication client-side plugin to use.",
|
2011-06-06 12:27:05 +02:00
|
|
|
&opt_default_auth, &opt_default_auth, 0,
|
2011-01-16 04:59:05 +01:00
|
|
|
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2022-01-04 19:09:40 +01:00
|
|
|
{"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},
|
2007-04-18 13:21:39 +02:00
|
|
|
{"force", 'f', "Force execution of mysqlcheck even if mysql_upgrade "
|
2018-11-07 12:16:29 +01:00
|
|
|
"has already been executed for the current version of MariaDB.",
|
2022-01-04 19:09:40 +01:00
|
|
|
&opt_not_used, &opt_not_used, 0 , GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2010-09-06 01:15:34 +02:00
|
|
|
{"host", 'h', "Connect to host.", 0,
|
2007-04-18 13:21:39 +02:00
|
|
|
0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
{"password", 'p',
|
2010-02-04 13:39:42 +01:00
|
|
|
"Password to use when connecting to server. If password is not given,"
|
Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.
Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.
As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.
The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.
client/mysql.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysql_upgrade.c:
Remove now-unnecessary casts.
client/mysqladmin.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysqlbinlog.cc:
Remove now-unnecessary casts.
client/mysqlcheck.c:
Remove now-unnecessary casts.
client/mysqldump.c:
Remove now-unnecessary casts.
client/mysqlimport.c:
Remove now-unnecessary casts.
client/mysqlshow.c:
Remove now-unnecessary casts.
client/mysqlslap.c:
Remove now-unnecessary casts.
client/mysqltest.cc:
Remove now-unnecessary casts.
extra/comp_err.c:
Remove now-unnecessary casts.
extra/my_print_defaults.c:
Remove now-unnecessary casts.
Break up large strings.
extra/mysql_waitpid.c:
Remove now-unnecessary casts.
extra/perror.c:
Remove now-unnecessary casts.
extra/resolve_stack_dump.c:
Remove now-unnecessary casts.
extra/resolveip.c:
Remove now-unnecessary casts.
include/my_getopt.h:
Use a void pointer type as the opaque type to avoid problems with type
incompatibility -- GCC issues warnings when the type name is not type
compatible with a operand. As a side bonus, a explicit cast won't be
necessary anymore.
include/sslopt-longopts.h:
Remove now-unnecessary casts.
Break up large strings.
mysys/my_getopt.c:
Update opaque type and introduce a type definition for the
argument to my_getopt_register_get_addr.
server-tools/instance-manager/options.cc:
Remove now-unnecessary casts.
sql/mysqld.cc:
Remove now-unnecessary casts.
Break up large strings.
Update mysql_getopt_value prototype (the old prototype
was different from the definition anyway).
sql/sql_plugin.cc:
The type of a pointer to a function must be compatible with the
pointed-to function type, otherwise the behavior is undefined.
sql/table.cc:
The variable buf pointer to pointer to pointer to constant char
could improperly alias a incompatible type in call to fix_type_
pointers. Since this was actually dead code, it is simply removed.
sql/unireg.cc:
Remove call to get_form_pos. The code creates a new FRM file which
is always truncated and writes the form position as 0. Hence, no
need to retrieve it, we now for sure it is 0.
storage/archive/archive_reader.c:
Remove now-unnecessary casts.
storage/myisam/ft_nlq_search.c:
Read weight directly from the buffer.
storage/myisam/fulltext.h:
Add explanation about the type duality of a key buffer.
Add accessor macro to retrieve a FT float value.
storage/myisam/mi_test1.c:
Remove now-unnecessary casts.
storage/myisam/myisam_ftdump.c:
Read weight directly from the buffer.
storage/myisam/myisamchk.c:
Remove now-unnecessary casts.
storage/myisam/myisamlog.c:
A pointer to char was used to alias a pointer to pointer to
unsigned char, thus violating strict aliasing rules.
storage/myisam/myisampack.c:
Remove now-unnecessary casts.
strings/decimal.c:
Remove aliasing violation, printing the value is enough for
debugging purposes.
tests/mysql_client_test.c:
Remove now-unnecessary casts.
2010-06-10 22:16:43 +02:00
|
|
|
" it's solicited on the tty.", &opt_password,&opt_password,
|
2007-04-18 13:21:39 +02:00
|
|
|
0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
|
2021-06-06 13:21:03 +02:00
|
|
|
#ifdef _WIN32
|
2007-04-18 13:21:39 +02:00
|
|
|
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0,
|
2006-11-08 03:45:50 +01:00
|
|
|
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
|
|
|
#endif
|
2011-01-16 04:59:05 +01:00
|
|
|
{"plugin_dir", OPT_PLUGIN_DIR, "Directory for client-side plugins.",
|
2011-06-06 12:27:05 +02:00
|
|
|
&opt_plugin_dir, &opt_plugin_dir, 0,
|
2011-01-16 04:59:05 +01:00
|
|
|
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
Bug #15327: configure: --with-tcp-port option being partially ignored
make sure that if builder configured with a non-standard (!= 3306)
default TCP port that value actually gets used throughout. if they
didn't configure a value, assume "use a sensible default", which
will be read from /etc/services or, failing that, from the factory
default. That makes the order of preference
- command-line option
- my.cnf, where applicable
- $MYSQL_TCP_PORT environment variable
- /etc/services (unless configured --with-tcp-port)
- default port (--with-tcp-port=... or factory default)
client/mysql.cc:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
client/mysql_upgrade.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
client/mysqladmin.cc:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
client/mysqlbinlog.cc:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
client/mysqlcheck.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
client/mysqldump.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
client/mysqlimport.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
client/mysqlmanagerc.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
configure.in:
Bug #15327: configure: --with-tcp-port option being partially ignored
If MYSQL_TCP_PORT defaulted in configure (factory default 3306
at the time of this writing), set MYSQL_TCP_PORT to factory
default, then clear factory default after. That way, we lose no
information, and we can distinguish between "defaulted" and the
pathological case "builder specifically configured a port that
coincides with factory default." This can in theory happen if
builder configures and builds several servers from a script
(--with-tcp-port=3306, --with-tcp-port=3316, --with-tcp-port=3326).
Not all that probable, but much preferable to having more "magic"
happen in the server when we can solve this without any guesswork.
client/mysqlshow.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
client/mysqltest.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
include/mysql_version.h.in:
Bug #15327: configure: --with-tcp-port option being partially ignored
make factory default for TCP port available as MYSQL_PORT_DEFAULT
if build-time configured with a different default. (0 if unchanged)
libmysql/libmysql.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
initialize default tcp port for client, like so:
- if user configured --with-tcp-port, use that value as default
- otherwise assume "use a good default": search mysqld/tcp in
/etc/services; if that doesn't exist, use factory default (3306)
- environment variable MYSQL_TCP_PORT overrides this default
- command-line option overrides all of the above
mysql-test/Makefile.am:
Bug #15327: configure: --with-tcp-port option being partially ignored
make factory default for TCP port available as MYSQL_TCP_PORT_DEFAULT
if build-time configured with a different default. (0 if unchanged)
mysql-test/mysql-test-run-shell.sh:
Bug #15327: configure: --with-tcp-port option being partially ignored
set up MYSQL_TCP_PORT if not already set in environment:
- if user configured --with-tcp-port, use that value as default
- otherwise assume "use a good default": search mysqld/tcp in
/etc/services; if that doesn't exist, use factory default (3306)
netware/mysql_test_run.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
account for non-standard default port-no. configured at build-time
netware/mysqld_safe.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
account for non-standard default port-no. configured at build-time
scripts/Makefile.am:
Bug #15327: configure: --with-tcp-port option being partially ignored
make factory default for TCP port available as MYSQL_TCP_PORT_DEFAULT
if build-time configured with a different default. (0 if unchanged)
scripts/mysql_config.sh:
Bug #15327: configure: --with-tcp-port option being partially ignored
set up MYSQL_TCP_PORT if not already set in environment:
- if user configured --with-tcp-port, use that value as default
- otherwise assume "use a good default": search mysqld/tcp in
/etc/services; if that doesn't exist, use factory default (3306)
scripts/mysql_fix_privilege_tables.sh:
Bug #15327: configure: --with-tcp-port option being partially ignored
clarifying notice only
scripts/mysqld_safe-watch.sh:
Bug #15327: configure: --with-tcp-port option being partially ignored
account for non-standard default port-no. configured at build-time
server-tools/instance-manager/priv.h:
Bug #15327: configure: --with-tcp-port option being partially ignored
account for non-standard default port-no. configured at build-time
sql/mysqld.cc:
Bug #15327: configure: --with-tcp-port option being partially ignored
if builder specifically requested a default port, use that
(even if it coincides with our factory default).
only if they didn't do we check /etc/services (and, failing
on that, fall back to the factory default of 3306).
either default can be overridden by the environment variable
MYSQL_TCP_PORT, which in turn can be overridden with command
line options.
tests/mysql_client_test.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
tests/ssl_test.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
account for non-standard default port-no. configured at build-time
tests/thread_test.c:
Bug #15327: configure: --with-tcp-port option being partially ignored
make help on --port a little more clear
2007-09-13 16:19:46 +02:00
|
|
|
{"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},
|
2006-04-28 06:07:25 +02:00
|
|
|
{"protocol", OPT_MYSQL_PROTOCOL,
|
2018-08-20 14:06:33 +02:00
|
|
|
"The protocol to use for connection (tcp, socket, pipe).",
|
2006-04-28 06:07:25 +02:00
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2011-04-25 17:22:25 +02:00
|
|
|
{"silent", OPT_SILENT, "Print less information", &opt_silent,
|
2010-09-05 11:39:17 +02:00
|
|
|
&opt_silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2010-02-04 13:39:42 +01:00
|
|
|
{"socket", 'S', "The socket file to use for connection.",
|
2007-04-18 13:21:39 +02:00
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2009-04-28 20:26:31 +02:00
|
|
|
#include <sslopt-longopts.h>
|
2010-02-04 13:39:42 +01:00
|
|
|
{"tmpdir", 't', "Directory for temporary files.",
|
2008-05-02 14:41:19 +02:00
|
|
|
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2014-08-14 14:38:08 +02:00
|
|
|
{"upgrade-system-tables", 's', "Only upgrade the system tables in the mysql database. Tables in other databases are not checked or touched.",
|
2010-06-11 03:30:49 +02:00
|
|
|
&opt_systables_only, &opt_systables_only, 0,
|
2009-10-28 11:02:00 +01:00
|
|
|
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2020-05-08 14:11:41 +02:00
|
|
|
{"user", 'u', "User for login.", &opt_user,
|
Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.
Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.
As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.
The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.
client/mysql.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysql_upgrade.c:
Remove now-unnecessary casts.
client/mysqladmin.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysqlbinlog.cc:
Remove now-unnecessary casts.
client/mysqlcheck.c:
Remove now-unnecessary casts.
client/mysqldump.c:
Remove now-unnecessary casts.
client/mysqlimport.c:
Remove now-unnecessary casts.
client/mysqlshow.c:
Remove now-unnecessary casts.
client/mysqlslap.c:
Remove now-unnecessary casts.
client/mysqltest.cc:
Remove now-unnecessary casts.
extra/comp_err.c:
Remove now-unnecessary casts.
extra/my_print_defaults.c:
Remove now-unnecessary casts.
Break up large strings.
extra/mysql_waitpid.c:
Remove now-unnecessary casts.
extra/perror.c:
Remove now-unnecessary casts.
extra/resolve_stack_dump.c:
Remove now-unnecessary casts.
extra/resolveip.c:
Remove now-unnecessary casts.
include/my_getopt.h:
Use a void pointer type as the opaque type to avoid problems with type
incompatibility -- GCC issues warnings when the type name is not type
compatible with a operand. As a side bonus, a explicit cast won't be
necessary anymore.
include/sslopt-longopts.h:
Remove now-unnecessary casts.
Break up large strings.
mysys/my_getopt.c:
Update opaque type and introduce a type definition for the
argument to my_getopt_register_get_addr.
server-tools/instance-manager/options.cc:
Remove now-unnecessary casts.
sql/mysqld.cc:
Remove now-unnecessary casts.
Break up large strings.
Update mysql_getopt_value prototype (the old prototype
was different from the definition anyway).
sql/sql_plugin.cc:
The type of a pointer to a function must be compatible with the
pointed-to function type, otherwise the behavior is undefined.
sql/table.cc:
The variable buf pointer to pointer to pointer to constant char
could improperly alias a incompatible type in call to fix_type_
pointers. Since this was actually dead code, it is simply removed.
sql/unireg.cc:
Remove call to get_form_pos. The code creates a new FRM file which
is always truncated and writes the form position as 0. Hence, no
need to retrieve it, we now for sure it is 0.
storage/archive/archive_reader.c:
Remove now-unnecessary casts.
storage/myisam/ft_nlq_search.c:
Read weight directly from the buffer.
storage/myisam/fulltext.h:
Add explanation about the type duality of a key buffer.
Add accessor macro to retrieve a FT float value.
storage/myisam/mi_test1.c:
Remove now-unnecessary casts.
storage/myisam/myisam_ftdump.c:
Read weight directly from the buffer.
storage/myisam/myisamchk.c:
Remove now-unnecessary casts.
storage/myisam/myisamlog.c:
A pointer to char was used to alias a pointer to pointer to
unsigned char, thus violating strict aliasing rules.
storage/myisam/myisampack.c:
Remove now-unnecessary casts.
strings/decimal.c:
Remove aliasing violation, printing the value is enough for
debugging purposes.
tests/mysql_client_test.c:
Remove now-unnecessary casts.
2010-06-10 22:16:43 +02:00
|
|
|
&opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
|
2023-03-06 18:32:03 +01:00
|
|
|
{"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.",
|
2010-09-05 11:39:17 +02:00
|
|
|
&opt_not_used, &opt_not_used, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
|
2013-01-10 23:53:07 +01:00
|
|
|
{"version", 'V', "Output version information and exit.", 0, 0, 0,
|
|
|
|
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
|
2014-08-14 14:38:08 +02:00
|
|
|
{"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,
|
2007-04-18 13:21:39 +02:00
|
|
|
GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0},
|
2017-11-20 10:00:44 +01:00
|
|
|
{"write-binlog", OPT_WRITE_BINLOG, "All commands including those "
|
|
|
|
"issued by mysqlcheck are written to the binary log.",
|
Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.
Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.
As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.
The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.
client/mysql.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysql_upgrade.c:
Remove now-unnecessary casts.
client/mysqladmin.cc:
Remove now-unnecessary casts.
Break up large strings.
client/mysqlbinlog.cc:
Remove now-unnecessary casts.
client/mysqlcheck.c:
Remove now-unnecessary casts.
client/mysqldump.c:
Remove now-unnecessary casts.
client/mysqlimport.c:
Remove now-unnecessary casts.
client/mysqlshow.c:
Remove now-unnecessary casts.
client/mysqlslap.c:
Remove now-unnecessary casts.
client/mysqltest.cc:
Remove now-unnecessary casts.
extra/comp_err.c:
Remove now-unnecessary casts.
extra/my_print_defaults.c:
Remove now-unnecessary casts.
Break up large strings.
extra/mysql_waitpid.c:
Remove now-unnecessary casts.
extra/perror.c:
Remove now-unnecessary casts.
extra/resolve_stack_dump.c:
Remove now-unnecessary casts.
extra/resolveip.c:
Remove now-unnecessary casts.
include/my_getopt.h:
Use a void pointer type as the opaque type to avoid problems with type
incompatibility -- GCC issues warnings when the type name is not type
compatible with a operand. As a side bonus, a explicit cast won't be
necessary anymore.
include/sslopt-longopts.h:
Remove now-unnecessary casts.
Break up large strings.
mysys/my_getopt.c:
Update opaque type and introduce a type definition for the
argument to my_getopt_register_get_addr.
server-tools/instance-manager/options.cc:
Remove now-unnecessary casts.
sql/mysqld.cc:
Remove now-unnecessary casts.
Break up large strings.
Update mysql_getopt_value prototype (the old prototype
was different from the definition anyway).
sql/sql_plugin.cc:
The type of a pointer to a function must be compatible with the
pointed-to function type, otherwise the behavior is undefined.
sql/table.cc:
The variable buf pointer to pointer to pointer to constant char
could improperly alias a incompatible type in call to fix_type_
pointers. Since this was actually dead code, it is simply removed.
sql/unireg.cc:
Remove call to get_form_pos. The code creates a new FRM file which
is always truncated and writes the form position as 0. Hence, no
need to retrieve it, we now for sure it is 0.
storage/archive/archive_reader.c:
Remove now-unnecessary casts.
storage/myisam/ft_nlq_search.c:
Read weight directly from the buffer.
storage/myisam/fulltext.h:
Add explanation about the type duality of a key buffer.
Add accessor macro to retrieve a FT float value.
storage/myisam/mi_test1.c:
Remove now-unnecessary casts.
storage/myisam/myisam_ftdump.c:
Read weight directly from the buffer.
storage/myisam/myisamchk.c:
Remove now-unnecessary casts.
storage/myisam/myisamlog.c:
A pointer to char was used to alias a pointer to pointer to
unsigned char, thus violating strict aliasing rules.
storage/myisam/myisampack.c:
Remove now-unnecessary casts.
strings/decimal.c:
Remove aliasing violation, printing the value is enough for
debugging purposes.
tests/mysql_client_test.c:
Remove now-unnecessary casts.
2010-06-10 22:16:43 +02:00
|
|
|
&opt_write_binlog, &opt_write_binlog, 0, GET_BOOL, NO_ARG,
|
2013-11-11 09:31:20 +01:00
|
|
|
0, 0, 0, 0, 0, 0},
|
2006-04-28 06:07:25 +02:00
|
|
|
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
|
|
|
|
};
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2014-01-22 14:16:57 +01:00
|
|
|
static const char *load_default_groups[]=
|
|
|
|
{
|
|
|
|
"client", /* Read settings how to connect to server */
|
|
|
|
"mysql_upgrade", /* Read special settings for mysql_upgrade */
|
2019-07-18 14:32:22 +02:00
|
|
|
"mariadb-upgrade", /* Read special settings for mysql_upgrade */
|
2014-01-22 14:16:57 +01:00
|
|
|
"client-server", /* Reads settings common between client & server */
|
|
|
|
"client-mariadb", /* Read mariadb unique client settings */
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static void free_used_memory(void)
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Free memory allocated by 'load_defaults' */
|
2016-02-14 17:33:20 +01:00
|
|
|
if (defaults_argv)
|
|
|
|
free_defaults(defaults_argv);
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2007-04-19 21:30:46 +02:00
|
|
|
dynstr_free(&ds_args);
|
2009-05-27 10:24:25 +02:00
|
|
|
dynstr_free(&conn_args);
|
2021-01-20 21:59:51 +01:00
|
|
|
dynstr_free(&ds_plugin_data_types);
|
2015-12-08 10:16:41 +01:00
|
|
|
if (cnf_file_path)
|
|
|
|
my_delete(cnf_file_path, MYF(MY_WME));
|
2022-01-04 19:09:40 +01:00
|
|
|
if (info_file >= 0)
|
|
|
|
{
|
|
|
|
(void) my_lock(info_file, F_UNLCK, 0, 1, MYF(0));
|
|
|
|
my_close(info_file, MYF(MY_WME));
|
|
|
|
info_file= -1;
|
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static void die(const char *fmt, ...)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
va_list args;
|
|
|
|
DBUG_ENTER("die");
|
|
|
|
|
|
|
|
/* Print the error message */
|
2023-03-06 18:32:03 +01:00
|
|
|
print_conn_args("mariadb-check");
|
2014-01-22 14:16:57 +01:00
|
|
|
fflush(stdout);
|
2007-04-18 13:21:39 +02:00
|
|
|
va_start(args, fmt);
|
|
|
|
if (fmt)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "FATAL ERROR: ");
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
fflush(stderr);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
free_used_memory();
|
2007-08-01 21:59:05 +02:00
|
|
|
my_end(my_end_arg);
|
2007-04-18 13:21:39 +02:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void verbose(const char *fmt, ...)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
va_list args;
|
|
|
|
|
2010-09-05 11:39:17 +02:00
|
|
|
if (opt_silent)
|
2007-04-18 13:21:39 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Print the verbose message */
|
|
|
|
va_start(args, fmt);
|
|
|
|
if (fmt)
|
|
|
|
{
|
|
|
|
vfprintf(stdout, fmt, args);
|
|
|
|
fprintf(stdout, "\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
static void print_error(const char *error_msg, DYNAMIC_STRING *output)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%s\n", error_msg);
|
|
|
|
fprintf(stderr, "%s", output->str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Add one option - passed to mysql_upgrade on command line
|
2007-04-19 21:30:46 +02:00
|
|
|
or by defaults file(my.cnf) - to a dynamic string, in
|
|
|
|
this way we pass the same arguments on to mysql and mysql_check
|
2007-04-18 13:21:39 +02:00
|
|
|
*/
|
|
|
|
|
2015-12-08 10:16:41 +01:00
|
|
|
static void add_one_option_cmd_line(DYNAMIC_STRING *ds,
|
2022-02-10 11:28:46 +01:00
|
|
|
const char *name,
|
|
|
|
const char *arg)
|
2007-04-19 21:30:46 +02:00
|
|
|
{
|
2015-12-08 10:13:13 +01:00
|
|
|
dynstr_append(ds, "--");
|
2022-02-10 11:28:46 +01:00
|
|
|
dynstr_append(ds, name);
|
2015-12-08 10:13:13 +01:00
|
|
|
if (arg)
|
2007-04-18 13:21:39 +02:00
|
|
|
{
|
2015-12-08 10:13:13 +01:00
|
|
|
dynstr_append(ds, "=");
|
|
|
|
dynstr_append_os_quoted(ds, arg, NullS);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2009-05-27 10:24:25 +02:00
|
|
|
dynstr_append(ds, " ");
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
|
2015-12-08 10:16:41 +01:00
|
|
|
static void add_one_option_cnf_file(DYNAMIC_STRING *ds,
|
2022-02-10 11:28:46 +01:00
|
|
|
const char *name,
|
|
|
|
const char *arg)
|
2015-12-08 10:16:41 +01:00
|
|
|
{
|
2022-02-10 11:28:46 +01:00
|
|
|
dynstr_append(ds, name);
|
2015-12-08 10:16:41 +01:00
|
|
|
if (arg)
|
|
|
|
{
|
|
|
|
dynstr_append(ds, "=");
|
|
|
|
dynstr_append_os_quoted(ds, arg, NullS);
|
|
|
|
}
|
|
|
|
dynstr_append(ds, "\n");
|
|
|
|
}
|
2006-11-08 03:45:50 +01:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
static my_bool
|
2021-02-05 13:57:46 +01:00
|
|
|
get_one_option(const struct my_option *opt, const char *argument,
|
2019-09-29 16:30:57 +02:00
|
|
|
const char *filename __attribute__((unused)))
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
my_bool add_option= TRUE;
|
|
|
|
|
2019-09-29 16:30:57 +02:00
|
|
|
switch (opt->id) {
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
case '?':
|
2022-12-11 00:11:43 +01:00
|
|
|
print_version();
|
2012-08-07 15:37:13 +02:00
|
|
|
puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000"));
|
2014-01-22 14:16:57 +01:00
|
|
|
puts("MariaDB utility for upgrading databases to new MariaDB versions.");
|
|
|
|
print_defaults("my", load_default_groups);
|
|
|
|
puts("");
|
2006-04-28 06:07:25 +02:00
|
|
|
my_print_help(my_long_options);
|
2014-01-22 14:16:57 +01:00
|
|
|
my_print_variables(my_long_options);
|
2012-03-23 10:53:25 +01:00
|
|
|
die(0);
|
2007-04-18 13:21:39 +02:00
|
|
|
break;
|
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
case '#':
|
|
|
|
DBUG_PUSH(argument ? argument : default_dbug_option);
|
2007-04-18 13:21:39 +02:00
|
|
|
add_option= FALSE;
|
2007-08-02 06:49:29 +02:00
|
|
|
debug_check_flag= 1;
|
2006-04-28 06:07:25 +02:00
|
|
|
break;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
case 'p':
|
2009-05-07 19:51:55 +02:00
|
|
|
if (argument == disabled_my_option)
|
2009-06-03 13:18:12 +02:00
|
|
|
argument= (char*) ""; /* Don't require password */
|
2007-04-18 13:21:39 +02:00
|
|
|
add_option= FALSE;
|
2006-04-28 06:07:25 +02:00
|
|
|
if (argument)
|
|
|
|
{
|
2021-02-05 13:57:46 +01:00
|
|
|
/*
|
|
|
|
One should not really change the argument, but we make an
|
|
|
|
exception for passwords
|
|
|
|
*/
|
|
|
|
char *start= (char*) argument;
|
2007-04-19 21:30:46 +02:00
|
|
|
/* Add password to ds_args before overwriting the arg with x's */
|
2022-02-10 11:28:46 +01:00
|
|
|
add_one_option_cnf_file(&ds_args, opt->name, argument);
|
2006-04-28 06:07:25 +02:00
|
|
|
while (*argument)
|
2021-02-05 13:57:46 +01:00
|
|
|
*(char*)argument++= 'x'; /* Destroy argument */
|
|
|
|
if (*start)
|
|
|
|
start[1]= 0;
|
2006-04-28 06:07:25 +02:00
|
|
|
tty_password= 0;
|
|
|
|
}
|
2015-12-08 10:13:13 +01:00
|
|
|
else
|
|
|
|
tty_password= 1;
|
2006-04-28 06:07:25 +02:00
|
|
|
break;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2008-05-02 14:41:19 +02:00
|
|
|
case 't':
|
|
|
|
strnmov(opt_tmpdir, argument, sizeof(opt_tmpdir));
|
|
|
|
add_option= FALSE;
|
|
|
|
break;
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
case 'b': /* --basedir */
|
|
|
|
case 'd': /* --datadir */
|
2009-05-19 19:39:03 +02:00
|
|
|
fprintf(stderr, "%s: the '--%s' option is always ignored\n",
|
2019-09-29 16:30:57 +02:00
|
|
|
my_progname, opt->id == 'b' ? "basedir" : "datadir");
|
2009-05-19 19:39:03 +02:00
|
|
|
/* FALLTHROUGH */
|
|
|
|
|
2013-03-21 18:21:40 +01:00
|
|
|
case 'k': /* --version-check */
|
2009-05-19 19:39:03 +02:00
|
|
|
case 'v': /* --verbose */
|
2010-09-05 11:39:17 +02:00
|
|
|
opt_verbose++;
|
|
|
|
if (argument == disabled_my_option)
|
|
|
|
{
|
|
|
|
opt_verbose= 0;
|
|
|
|
opt_silent= 1;
|
|
|
|
}
|
|
|
|
add_option= 0;
|
|
|
|
break;
|
2013-01-10 23:53:07 +01:00
|
|
|
case 'V':
|
|
|
|
printf("%s Ver %s Distrib %s, for %s (%s)\n",
|
|
|
|
my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE);
|
|
|
|
die(0);
|
|
|
|
break;
|
2022-01-04 19:09:40 +01:00
|
|
|
case 'f': /* --force */
|
|
|
|
opt_force++;
|
|
|
|
if (argument == disabled_my_option)
|
|
|
|
opt_force= 0;
|
|
|
|
add_option= 0;
|
|
|
|
break;
|
2011-04-25 17:22:25 +02:00
|
|
|
case OPT_SILENT:
|
2010-09-05 11:39:17 +02:00
|
|
|
opt_verbose= 0;
|
|
|
|
add_option= 0;
|
|
|
|
break;
|
2022-01-04 19:09:40 +01:00
|
|
|
case OPT_CHECK_IF_UPGRADE_NEEDED: /* --check-if-upgrade-needed */
|
Bug#11827359 60223: MYSQL_UPGRADE PROBLEM WITH
OPTION SKIP-WRITE-BINLOG
System tables were not getting upgraded when
mysql_upgrade was run with --skip-write-binlog
option. (Same for --write-binlog.) Also, with
this option, mysql_upgrade_info file was not
getting created after the upgrade.
mysql_upgrade makes use of mysql client tool in
order to run upgrade scripts, while doing so it
passes some of the command line options (used to
start mysql_upgrade) directly to mysql client.
The reason behind this bug being, some options
like skip-write-binlog and upgrade-system-tables
were being passed to mysql tool along with other
options, and hence mysql execution failed due
presence of these invalid options.
Fixed this issue by filtering out the above mentioned
options from the list of options that will be passed to
mysql and mysqlcheck tools. However, since --write-binlog
is supported by mysqlcheck, this option would be used
explicitly while running mysqlcheck. (not part of patch,
already there)
Checking the contents of general log after the upgrade
is not doable via an mtr test. So performed manual test.
Added a test to verify the creation of mysql_upgrade_info.
client/mysql_upgrade.c:
Bug#11827359 60223: MYSQL_UPGRADE PROBLEM WITH
OPTION SKIP-WRITE-BINLOG
With this patch, --upgrade-system-tables and
--write-binlog options will not be added to the
list of options, used to start mysql and mysqlcheck
tools.
mysql-test/r/mysql_upgrade.result:
Added a testcase for Bug#11827359.
mysql-test/t/mysql_upgrade.test:
Added a testcase for Bug#11827359.
2011-11-15 13:18:42 +01:00
|
|
|
case 's': /* --upgrade-system-tables */
|
|
|
|
case OPT_WRITE_BINLOG: /* --write-binlog */
|
2007-04-18 13:21:39 +02:00
|
|
|
add_option= FALSE;
|
2006-11-08 03:45:50 +01:00
|
|
|
break;
|
2009-05-27 10:24:25 +02:00
|
|
|
|
|
|
|
case 'h': /* --host */
|
|
|
|
case 'W': /* --pipe */
|
|
|
|
case 'P': /* --port */
|
|
|
|
case 'S': /* --socket */
|
|
|
|
case OPT_MYSQL_PROTOCOL: /* --protocol */
|
2011-01-16 04:59:05 +01:00
|
|
|
case OPT_PLUGIN_DIR: /* --plugin-dir */
|
|
|
|
case OPT_DEFAULT_AUTH: /* --default-auth */
|
2022-02-10 11:28:46 +01:00
|
|
|
add_one_option_cmd_line(&conn_args, opt->name, argument);
|
2009-05-27 10:24:25 +02:00
|
|
|
break;
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (add_option)
|
|
|
|
{
|
|
|
|
/*
|
2015-12-08 10:13:13 +01:00
|
|
|
This is an option that is accepted by mysql_upgrade just so
|
2007-04-18 13:21:39 +02:00
|
|
|
it can be passed on to "mysql" and "mysqlcheck"
|
2007-04-19 21:30:46 +02:00
|
|
|
Save it in the ds_args string
|
2007-04-18 13:21:39 +02:00
|
|
|
*/
|
2022-02-10 11:28:46 +01:00
|
|
|
add_one_option_cnf_file(&ds_args, opt->name, argument);
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
/* Convert the specified version string into the numeric format. */
|
|
|
|
|
|
|
|
static ulong STDCALL calc_server_version(char *some_version)
|
|
|
|
{
|
|
|
|
uint major, minor, version;
|
|
|
|
char *point= some_version, *end_point;
|
|
|
|
major= (uint) strtoul(point, &end_point, 10); point=end_point+1;
|
|
|
|
minor= (uint) strtoul(point, &end_point, 10); point=end_point+1;
|
|
|
|
version= (uint) strtoul(point, &end_point, 10);
|
|
|
|
return (ulong) major * 10000L + (ulong)(minor * 100 + version);
|
|
|
|
}
|
|
|
|
|
2008-08-07 18:24:39 +02:00
|
|
|
/**
|
|
|
|
Run a command using the shell, storing its output in the supplied dynamic
|
|
|
|
string.
|
|
|
|
*/
|
2007-04-18 13:21:39 +02:00
|
|
|
static int run_command(char* cmd,
|
|
|
|
DYNAMIC_STRING *ds_res)
|
|
|
|
{
|
|
|
|
char buf[512]= {0};
|
|
|
|
FILE *res_file;
|
2007-04-23 13:27:55 +02:00
|
|
|
int error;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2014-08-14 14:38:08 +02:00
|
|
|
if (opt_verbose >= 4)
|
|
|
|
puts(cmd);
|
|
|
|
|
2019-11-21 01:51:34 +01:00
|
|
|
if (!(res_file= my_popen(cmd, "r")))
|
2007-04-18 13:21:39 +02:00
|
|
|
die("popen(\"%s\", \"r\") failed", cmd);
|
|
|
|
|
|
|
|
while (fgets(buf, sizeof(buf), res_file))
|
|
|
|
{
|
2019-11-21 01:51:34 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
/* Strip '\r' off newlines. */
|
|
|
|
size_t len = strlen(buf);
|
|
|
|
if (len > 1 && buf[len - 2] == '\r' && buf[len - 1] == '\n')
|
|
|
|
{
|
|
|
|
buf[len - 2] = '\n';
|
|
|
|
buf[len - 1] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
2007-04-18 13:21:39 +02:00
|
|
|
DBUG_PRINT("info", ("buf: %s", buf));
|
|
|
|
if(ds_res)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Save the output of this command in the supplied string */
|
|
|
|
dynstr_append(ds_res, buf);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
else
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/* Print it directly on screen */
|
|
|
|
fprintf(stdout, "%s", buf);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2019-11-13 21:12:48 +01:00
|
|
|
error= my_pclose(res_file);
|
2007-04-23 13:27:55 +02:00
|
|
|
return WEXITSTATUS(error);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static int run_tool(char *tool_path, DYNAMIC_STRING *ds_res, ...)
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2006-11-08 03:45:50 +01:00
|
|
|
int ret;
|
2007-04-18 13:21:39 +02:00
|
|
|
const char* arg;
|
|
|
|
va_list args;
|
|
|
|
DYNAMIC_STRING ds_cmdline;
|
|
|
|
|
|
|
|
DBUG_ENTER("run_tool");
|
|
|
|
DBUG_PRINT("enter", ("tool_path: %s", tool_path));
|
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_cmdline, IF_WIN("\"", ""), FN_REFLEN, FN_REFLEN))
|
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
dynstr_append_os_quoted(&ds_cmdline, tool_path, NullS);
|
|
|
|
dynstr_append(&ds_cmdline, " ");
|
|
|
|
|
|
|
|
va_start(args, ds_res);
|
|
|
|
|
|
|
|
while ((arg= va_arg(args, char *)))
|
|
|
|
{
|
2015-12-08 10:13:13 +01:00
|
|
|
/* Options should already be os quoted */
|
|
|
|
dynstr_append(&ds_cmdline, arg);
|
2007-04-18 13:21:39 +02:00
|
|
|
dynstr_append(&ds_cmdline, " ");
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
va_end(args);
|
|
|
|
|
2021-06-06 13:21:03 +02:00
|
|
|
#ifdef _WIN32
|
2007-04-19 17:00:29 +02:00
|
|
|
dynstr_append(&ds_cmdline, "\"");
|
|
|
|
#endif
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
DBUG_PRINT("info", ("Running: %s", ds_cmdline.str));
|
|
|
|
ret= run_command(ds_cmdline.str, ds_res);
|
|
|
|
DBUG_PRINT("exit", ("ret: %d", ret));
|
|
|
|
dynstr_free(&ds_cmdline);
|
|
|
|
DBUG_RETURN(ret);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-07 18:24:39 +02:00
|
|
|
/**
|
|
|
|
Look for the filename of given tool, with the presumption that it is in the
|
|
|
|
same directory as mysql_upgrade and that the same executable-searching
|
|
|
|
mechanism will be used when we run our sub-shells with popen() later.
|
2007-04-18 13:21:39 +02:00
|
|
|
*/
|
2008-08-07 18:24:39 +02:00
|
|
|
static void find_tool(char *tool_executable_name, const char *tool_name,
|
|
|
|
const char *self_name)
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2008-08-07 18:24:39 +02:00
|
|
|
char *last_fn_libchar;
|
2007-04-18 13:21:39 +02:00
|
|
|
DYNAMIC_STRING ds_tmp;
|
|
|
|
DBUG_ENTER("find_tool");
|
|
|
|
DBUG_PRINT("enter", ("progname: %s", my_progname));
|
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_tmp, "", 32, 32))
|
|
|
|
die("Out of memory");
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2008-08-07 18:24:39 +02:00
|
|
|
last_fn_libchar= strrchr(self_name, FN_LIBCHAR);
|
|
|
|
|
|
|
|
if (last_fn_libchar == NULL)
|
2006-12-08 10:23:03 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
2008-08-07 18:24:39 +02:00
|
|
|
mysql_upgrade was found by the shell searching the path. A sibling
|
|
|
|
next to us should be found the same way.
|
2007-04-18 13:21:39 +02:00
|
|
|
*/
|
2008-08-07 18:24:39 +02:00
|
|
|
strncpy(tool_executable_name, tool_name, FN_REFLEN);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2008-08-07 18:24:39 +02:00
|
|
|
else
|
2007-08-27 10:25:34 +02:00
|
|
|
{
|
2009-03-20 15:27:53 +01:00
|
|
|
int len;
|
2008-08-11 15:08:21 +02:00
|
|
|
|
|
|
|
/*
|
2008-08-07 18:24:39 +02:00
|
|
|
mysql_upgrade was run absolutely or relatively. We can find a sibling
|
|
|
|
by replacing our name after the LIBCHAR with the new tool name.
|
|
|
|
*/
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2008-08-07 18:24:39 +02:00
|
|
|
/*
|
|
|
|
When running in a not yet installed build and using libtool,
|
|
|
|
the program(mysql_upgrade) will be in .libs/ and executed
|
|
|
|
through a libtool wrapper in order to use the dynamic libraries
|
|
|
|
from this build. The same must be done for the tools(mysql and
|
|
|
|
mysqlcheck). Thus if path ends in .libs/, step up one directory
|
|
|
|
and execute the tools from there
|
|
|
|
*/
|
|
|
|
if (((last_fn_libchar - 6) >= self_name) &&
|
|
|
|
(strncmp(last_fn_libchar - 5, ".libs", 5) == 0) &&
|
|
|
|
(*(last_fn_libchar - 6) == FN_LIBCHAR))
|
|
|
|
{
|
|
|
|
DBUG_PRINT("info", ("Chopping off \".libs\" from end of path"));
|
|
|
|
last_fn_libchar -= 6;
|
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2017-09-28 12:38:02 +02:00
|
|
|
len= (int)(last_fn_libchar - self_name);
|
2008-08-11 15:08:21 +02:00
|
|
|
|
2020-03-16 16:53:10 +01:00
|
|
|
my_snprintf(tool_executable_name, FN_REFLEN, "%.*b%c%s",
|
2008-08-11 15:08:21 +02:00
|
|
|
len, self_name, FN_LIBCHAR, tool_name);
|
2008-08-07 18:24:39 +02:00
|
|
|
}
|
2007-08-27 10:25:34 +02:00
|
|
|
|
2010-09-06 01:15:34 +02:00
|
|
|
if (opt_verbose)
|
|
|
|
verbose("Looking for '%s' as: %s", tool_name, tool_executable_name);
|
2007-08-27 10:25:34 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
Make sure it can be executed
|
|
|
|
*/
|
2008-08-07 18:24:39 +02:00
|
|
|
if (run_tool(tool_executable_name,
|
2007-08-27 10:25:34 +02:00
|
|
|
&ds_tmp, /* Get output from command, discard*/
|
Bug#14117012 - CHILD PROCESS MYSQL UTILITIES PICKING UP LOCAL
CONFIG FILES CAUSES TEST
Utility as "mysql_upgrade" forks "mysql"/"mysqlcheck". Attaching
"mysql_upgrade" shows following calls after forking "mysql" or
"mysql_check" when configuration file information is passed as
first argument to "mysql_upgrade".
strace -f ./mysql_upgrade --defaults-file=../pdb/my.cnf --socket=../pdb/mysql.sock -f
[pid 6254] stat("/etc/my.cnf", 0x7fff8e772680) = -1 ENOENT (No such file or directory)
[pid 6254] stat("/etc/mysql/my.cnf", 0x7fff8e772680) = -1 ENOENT (No such file or directory)
[pid 6254] stat("/usr/local/mysql/etc/my.cnf", 0x7fff8e772680) = -1 ENOENT (No such file or directory)
[pid 6254] stat("/home/user_name/.my.cnf", {st_mode=S_IFREG|0664, st_size=19, ...}) = 0
[pid 6254] open("/home/user_name/.my.cnf", O_RDONLY) = 3
But when tool forks "mysqlcheck"/"mysql", "--no-defaults" is passed
as first argument. Before forking, in function "find_tool" of
"mysql_upgrade", check is made to verify whether tool can be
executable or not by calling "mysqlcheck --help" and "mysql --help".
But argument "--no-defaults", "--defaults-file" or
"defaults-extra-file" is not passed to "mysql" and "mysqlcheck".
So my.cnf is searched in default paths.
Fix:
------
Modified code to pass "--no-defaults" as first argument to "mysql"
and "mysqlcheck" while checking tool can be executed or not.
2014-01-31 04:49:12 +01:00
|
|
|
"--no-defaults",
|
2007-08-27 10:25:34 +02:00
|
|
|
"--help",
|
|
|
|
"2>&1",
|
|
|
|
IF_WIN("> NUL", "> /dev/null"),
|
|
|
|
NULL))
|
2008-08-07 18:24:39 +02:00
|
|
|
die("Can't execute '%s'", tool_executable_name);
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
dynstr_free(&ds_tmp);
|
|
|
|
|
|
|
|
DBUG_VOID_RETURN;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
Run query using "mysql"
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int run_query(const char *query, DYNAMIC_STRING *ds_res,
|
|
|
|
my_bool force)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
File fd;
|
|
|
|
char query_file_path[FN_REFLEN];
|
2014-08-06 14:39:15 +02:00
|
|
|
#ifdef WITH_WSREP
|
2014-10-08 18:47:16 +02:00
|
|
|
/*
|
|
|
|
Strictly speaking, WITH_WSREP on the client only means that the
|
|
|
|
client was compiled with WSREP, it doesn't mean the server was,
|
|
|
|
so the server might not have WSREP_ON variable.
|
|
|
|
|
|
|
|
But mysql_upgrade is tightly bound to a specific server version
|
|
|
|
anyway - it was mysql_fix_privilege_tables_sql script embedded
|
|
|
|
into its binary - so even if it won't assume anything about server
|
2017-02-26 16:49:47 +01:00
|
|
|
wsrep-ness, it won't be any less server-dependent.
|
2014-10-08 18:47:16 +02:00
|
|
|
*/
|
2014-08-06 14:39:15 +02:00
|
|
|
const uchar sql_log_bin[]= "SET SQL_LOG_BIN=0, WSREP_ON=OFF;";
|
|
|
|
#else
|
2009-09-28 08:24:19 +02:00
|
|
|
const uchar sql_log_bin[]= "SET SQL_LOG_BIN=0;";
|
2014-08-06 14:39:15 +02:00
|
|
|
#endif /* WITH_WSREP */
|
2009-09-28 08:24:19 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
DBUG_ENTER("run_query");
|
|
|
|
DBUG_PRINT("enter", ("query: %s", query));
|
2010-03-09 10:18:46 +01:00
|
|
|
if ((fd= create_temp_file(query_file_path,
|
|
|
|
opt_tmpdir[0] ? opt_tmpdir : NULL,
|
2018-05-17 22:53:57 +02:00
|
|
|
"sql", O_SHARE, MYF(MY_WME))) < 0)
|
2007-04-18 13:21:39 +02:00
|
|
|
die("Failed to create temporary file for defaults");
|
|
|
|
|
2009-09-28 08:24:19 +02:00
|
|
|
/*
|
|
|
|
Master and slave should be upgraded separately. All statements executed
|
|
|
|
by mysql_upgrade will not be binlogged.
|
|
|
|
'SET SQL_LOG_BIN=0' is executed before any other statements.
|
|
|
|
*/
|
|
|
|
if (!opt_write_binlog)
|
|
|
|
{
|
|
|
|
if (my_write(fd, sql_log_bin, sizeof(sql_log_bin)-1,
|
|
|
|
MYF(MY_FNABP | MY_WME)))
|
|
|
|
{
|
2022-01-04 19:09:40 +01:00
|
|
|
my_close(fd, MYF(MY_WME));
|
2009-09-28 08:24:19 +02:00
|
|
|
my_delete(query_file_path, MYF(0));
|
2024-06-15 13:26:07 +02:00
|
|
|
die("Failed to write query to '%s'", query_file_path);
|
2009-09-28 08:24:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-13 15:11:25 +02:00
|
|
|
if (my_write(fd, (uchar*) query, strlen(query),
|
2007-04-18 13:21:39 +02:00
|
|
|
MYF(MY_FNABP | MY_WME)))
|
2007-10-09 04:30:41 +02:00
|
|
|
{
|
2022-01-04 19:09:40 +01:00
|
|
|
my_close(fd, MYF(MY_WME));
|
2007-10-09 04:30:41 +02:00
|
|
|
my_delete(query_file_path, MYF(0));
|
2024-06-15 13:26:07 +02:00
|
|
|
die("Failed to write query to '%s'", query_file_path);
|
2007-10-09 04:30:41 +02:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
ret= run_tool(mysql_path,
|
|
|
|
ds_res,
|
2015-12-08 10:16:41 +01:00
|
|
|
defaults_file,
|
2007-04-18 13:21:39 +02:00
|
|
|
"--database=mysql",
|
|
|
|
"--batch", /* Turns off pager etc. */
|
|
|
|
force ? "--force": "--skip-force",
|
2023-03-06 18:32:03 +01:00
|
|
|
opt_verbose >= 5 ? "--verbose" : "",
|
2024-06-15 13:26:07 +02:00
|
|
|
"--print-query-on-error",
|
2010-09-05 11:39:17 +02:00
|
|
|
ds_res || opt_silent ? "--silent": "",
|
2007-04-18 13:21:39 +02:00
|
|
|
"<",
|
|
|
|
query_file_path,
|
|
|
|
"2>&1",
|
|
|
|
NULL);
|
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
my_close(fd, MYF(MY_WME));
|
2007-08-03 12:54:06 +02:00
|
|
|
my_delete(query_file_path, MYF(0));
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2007-02-28 21:05:39 +01:00
|
|
|
DBUG_RETURN(ret);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Extract the value returned from result of "show variable like ..."
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int extract_variable_from_show(DYNAMIC_STRING* ds, char* value)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
char *value_start, *value_end;
|
2013-03-22 10:25:30 +01:00
|
|
|
size_t len;
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
The query returns "datadir\t<datadir>\n", skip past
|
|
|
|
the tab
|
|
|
|
*/
|
|
|
|
if ((value_start= strchr(ds->str, '\t')) == NULL)
|
|
|
|
return 1; /* Unexpected result */
|
|
|
|
value_start++;
|
|
|
|
|
|
|
|
/* Don't copy the ending newline */
|
2007-04-18 19:00:42 +02:00
|
|
|
if ((value_end= strchr(value_start, '\n')) == NULL)
|
2007-04-18 13:21:39 +02:00
|
|
|
return 1; /* Unexpected result */
|
|
|
|
|
2013-07-21 16:39:19 +02:00
|
|
|
len= (size_t) MY_MIN(FN_REFLEN, value_end-value_start);
|
2013-03-22 10:25:30 +01:00
|
|
|
strncpy(value, value_start, len);
|
|
|
|
value[len]= '\0';
|
2007-04-18 13:21:39 +02:00
|
|
|
return 0;
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
static int get_upgrade_info_file_name(char* name)
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
DYNAMIC_STRING ds_datadir;
|
|
|
|
DBUG_ENTER("get_upgrade_info_file_name");
|
|
|
|
|
|
|
|
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))
|
2006-11-08 03:45:50 +01:00
|
|
|
{
|
2022-01-04 19:09:40 +01:00
|
|
|
print_error("Reading datadir from the MariaDB server failed. Got the "
|
|
|
|
"following error when executing the 'mysql' command line client",
|
|
|
|
&ds_datadir);
|
2007-04-18 13:21:39 +02:00
|
|
|
dynstr_free(&ds_datadir);
|
|
|
|
DBUG_RETURN(1); /* Query failed */
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
dynstr_free(&ds_datadir);
|
|
|
|
|
2023-01-31 22:13:41 +01:00
|
|
|
fn_format(name, "mariadb_upgrade_info", name, "", MYF(0));
|
2007-04-18 13:21:39 +02:00
|
|
|
DBUG_PRINT("exit", ("name: %s", name));
|
|
|
|
DBUG_RETURN(0);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
static char upgrade_info_file[FN_REFLEN]= {0};
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2023-01-31 22:13:41 +01:00
|
|
|
Open or create mariadb_upgrade_info file in servers data dir.
|
2022-01-04 19:09:40 +01:00
|
|
|
|
|
|
|
Take a lock to ensure there cannot be any other mysql_upgrades
|
2022-08-08 00:07:39 +02:00
|
|
|
running concurrently
|
2022-01-04 19:09:40 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
const char *create_error_message=
|
|
|
|
"%sCould not open or create the upgrade info file '%s' in "
|
|
|
|
"the MariaDB Servers data directory, errno: %d (%s)\n";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void open_mysql_upgrade_file()
|
|
|
|
{
|
|
|
|
char errbuff[80];
|
2023-01-31 22:13:41 +01:00
|
|
|
char old_upgrade_info_file[FN_REFLEN]= {0};
|
|
|
|
size_t path_len;
|
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
if (get_upgrade_info_file_name(upgrade_info_file))
|
|
|
|
{
|
|
|
|
die("Upgrade failed");
|
|
|
|
}
|
2023-01-31 22:13:41 +01:00
|
|
|
|
|
|
|
// Delete old mysql_upgrade_info file
|
|
|
|
dirname_part(old_upgrade_info_file, upgrade_info_file, &path_len);
|
|
|
|
fn_format(old_upgrade_info_file, "mysql_upgrade_info", old_upgrade_info_file, "", MYF(0));
|
|
|
|
my_delete(old_upgrade_info_file, MYF(MY_IGNORE_ENOENT));
|
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Place holder for versions that require a major upgrade
|
|
|
|
|
2022-08-08 00:07:39 +02:00
|
|
|
@return 0 upgrade has already been run on this version
|
2022-01-04 19:09:40 +01:00
|
|
|
@return 1 upgrade has to be run
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int faulty_server_versions(const char *version)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
2023-01-31 22:13:41 +01:00
|
|
|
Read the content of mariadb_upgrade_info file and
|
2007-04-18 13:21:39 +02:00
|
|
|
compare the version number form file against
|
2016-03-04 01:09:37 +01:00
|
|
|
version number which mysql_upgrade was compiled for
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
NOTE
|
|
|
|
This is an optimization to avoid running mysql_upgrade
|
|
|
|
when it's already been performed for the particular
|
2022-01-04 19:09:40 +01:00
|
|
|
version of MariaDB.
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
In case the MariaDBL server can't return the upgrade info
|
2007-04-18 13:21:39 +02:00
|
|
|
file it's always better to report that the upgrade hasn't
|
|
|
|
been performed.
|
|
|
|
|
2022-08-08 00:07:39 +02:00
|
|
|
@return 0 Upgrade has already been run on this version
|
2022-01-04 19:09:40 +01:00
|
|
|
@return > 0 Upgrade has to be run
|
2007-04-18 13:21:39 +02:00
|
|
|
*/
|
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
static int upgrade_already_done(int silent)
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2022-01-04 19:09:40 +01:00
|
|
|
const char *version = MYSQL_SERVER_VERSION;
|
|
|
|
const char *s;
|
|
|
|
char *pos;
|
|
|
|
my_off_t length;
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
if (info_file < 0)
|
2009-10-26 12:35:42 +01:00
|
|
|
{
|
2022-01-04 19:09:40 +01:00
|
|
|
DBUG_ASSERT(opt_force > 1);
|
|
|
|
return 1; /* No info file and --force */
|
2009-10-26 12:35:42 +01:00
|
|
|
}
|
2007-02-28 21:23:35 +01:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
bzero(upgrade_from_version, sizeof(upgrade_from_version));
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
(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));
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
if (!length)
|
|
|
|
{
|
|
|
|
if (opt_verbose)
|
|
|
|
verbose("Empty or non existent %s. Assuming mysql_upgrade has to be run!",
|
|
|
|
upgrade_info_file);
|
|
|
|
return 1;
|
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
/* Remove possible \ŋ that may end in output */
|
|
|
|
if ((pos= strchr(upgrade_from_version, '\n')))
|
|
|
|
*pos= 0;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
if (faulty_server_versions(upgrade_from_version))
|
|
|
|
{
|
|
|
|
if (opt_verbose)
|
|
|
|
verbose("Upgrading from version %s requires mysql_upgrade to be run!",
|
|
|
|
upgrade_from_version);
|
|
|
|
return 2;
|
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
s= strchr(version, '.');
|
|
|
|
s= strchr(s + 1, '.');
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
if (strncmp(upgrade_from_version, version,
|
|
|
|
(size_t)(s - version + 1)))
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2022-01-04 19:09:40 +01:00
|
|
|
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);
|
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
die("Version mismatch (%s -> %s): Trying to downgrade from a higher to "
|
|
|
|
"lower version is not supported!",
|
|
|
|
upgrade_from_version, version);
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
2022-01-04 19:09:40 +01:00
|
|
|
if (!silent)
|
|
|
|
{
|
|
|
|
verbose("This installation of MariaDB is already upgraded to %s.\n"
|
2023-01-31 22:13:41 +01:00
|
|
|
"There is no need to run mariadb-upgrade again for %s.",
|
2022-01-04 19:09:40 +01:00
|
|
|
upgrade_from_version, version);
|
|
|
|
if (!opt_check_upgrade)
|
2023-04-14 16:40:41 +02:00
|
|
|
verbose("You can use --force if you still want to run mariadb-upgrade");
|
2022-01-04 19:09:40 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-31 22:13:41 +01:00
|
|
|
static void finish_mariadb_upgrade_info_file(void)
|
2022-01-04 19:09:40 +01:00
|
|
|
{
|
|
|
|
if (info_file < 0)
|
|
|
|
return;
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-23 13:07:49 +02:00
|
|
|
/* Write new version to file */
|
2022-01-04 19:09:40 +01:00
|
|
|
(void) my_seek(info_file, 0, SEEK_CUR, MYF(0));
|
|
|
|
(void) my_chsize(info_file, 0, 0, MYF(0));
|
|
|
|
(void) my_seek(info_file, 0, 0, MYF(0));
|
|
|
|
(void) my_write(info_file, (uchar*) MYSQL_SERVER_VERSION,
|
|
|
|
sizeof(MYSQL_SERVER_VERSION)-1, MYF(MY_WME));
|
|
|
|
(void) my_write(info_file, (uchar*) "\n", 1, MYF(MY_WME));
|
|
|
|
(void) my_lock(info_file, F_UNLCK, 0, 1, MYF(0));
|
2007-04-23 13:07:49 +02:00
|
|
|
|
|
|
|
/*
|
2022-01-04 19:09:40 +01:00
|
|
|
Check if the upgrade_info_file was properly created/updated
|
2007-04-23 13:07:49 +02:00
|
|
|
It's not a fatal error -> just print a message if it fails
|
|
|
|
*/
|
2022-01-04 19:09:40 +01:00
|
|
|
if (upgrade_already_done(1))
|
2007-04-18 13:21:39 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"Could not write to the upgrade info file '%s' in "
|
2022-01-04 19:09:40 +01:00
|
|
|
"the MariaDB Servers datadir, errno: %d\n",
|
2007-04-18 13:21:39 +02:00
|
|
|
upgrade_info_file, errno);
|
2022-01-04 19:09:40 +01:00
|
|
|
|
|
|
|
my_close(info_file, MYF(MY_WME));
|
|
|
|
info_file= -1;
|
2007-04-23 13:07:49 +02:00
|
|
|
return;
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2009-05-27 10:24:25 +02:00
|
|
|
/*
|
|
|
|
Print connection-related arguments.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void print_conn_args(const char *tool_name)
|
|
|
|
{
|
2010-09-05 11:39:17 +02:00
|
|
|
if (opt_verbose < 2)
|
|
|
|
return;
|
2009-05-27 10:24:25 +02:00
|
|
|
if (conn_args.str[0])
|
|
|
|
verbose("Running '%s' with connection arguments: %s", tool_name,
|
|
|
|
conn_args.str);
|
|
|
|
else
|
|
|
|
verbose("Running '%s with default connection arguments", tool_name);
|
|
|
|
}
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
2017-02-26 16:49:47 +01:00
|
|
|
Check and upgrade(if necessary) all tables
|
2007-04-18 13:21:39 +02:00
|
|
|
in the server using "mysqlcheck --check-upgrade .."
|
|
|
|
*/
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2015-05-04 22:00:24 +02:00
|
|
|
static int run_mysqlcheck_upgrade(my_bool mysql_db_only)
|
2007-04-18 13:21:39 +02:00
|
|
|
{
|
2015-05-04 22:00:24 +02:00
|
|
|
const char *what= mysql_db_only ? "mysql database" : "tables";
|
|
|
|
const char *arg1= mysql_db_only ? "--databases" : "--all-databases";
|
|
|
|
const char *arg2= mysql_db_only ? "mysql" : "--skip-database=mysql";
|
2015-04-14 03:26:13 +02:00
|
|
|
int retch;
|
2015-05-04 22:00:24 +02:00
|
|
|
if (opt_systables_only && !mysql_db_only)
|
2015-04-28 21:24:32 +02:00
|
|
|
{
|
2015-05-04 22:00:24 +02:00
|
|
|
verbose("Phase %d/%d: Checking and upgrading %s... Skipped",
|
|
|
|
++phase, phases_total, what);
|
2015-04-28 21:24:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-05-04 22:00:24 +02:00
|
|
|
verbose("Phase %d/%d: Checking and upgrading %s", ++phase, phases_total, what);
|
2022-09-28 16:20:23 +02:00
|
|
|
print_conn_args("mariadb-check");
|
2015-04-14 03:26:13 +02:00
|
|
|
retch= run_tool(mysqlcheck_path,
|
2007-04-18 13:21:39 +02:00
|
|
|
NULL, /* Send output from mysqlcheck directly to screen */
|
2015-12-08 10:16:41 +01:00
|
|
|
defaults_file,
|
2007-04-18 13:21:39 +02:00
|
|
|
"--check-upgrade",
|
|
|
|
"--auto-repair",
|
2014-08-14 14:38:08 +02:00
|
|
|
!opt_silent || opt_verbose >= 1 ? "--verbose" : "",
|
|
|
|
opt_verbose >= 2 ? "--verbose" : "",
|
|
|
|
opt_verbose >= 3 ? "--verbose" : "",
|
2010-09-05 11:39:17 +02:00
|
|
|
opt_silent ? "--silent": "",
|
2009-09-28 08:24:19 +02:00
|
|
|
opt_write_binlog ? "--write-binlog" : "--skip-write-binlog",
|
2014-08-06 13:27:44 +02:00
|
|
|
arg1, arg2,
|
2014-01-22 14:16:57 +01:00
|
|
|
"2>&1",
|
2008-12-09 09:30:49 +01:00
|
|
|
NULL);
|
2015-04-14 03:26:13 +02:00
|
|
|
return retch;
|
2008-12-09 09:30:49 +01:00
|
|
|
}
|
|
|
|
|
2015-04-12 09:05:02 +02:00
|
|
|
#define EVENTS_STRUCT_LEN 7000
|
|
|
|
|
|
|
|
static my_bool is_mysql()
|
|
|
|
{
|
|
|
|
my_bool ret= TRUE;
|
|
|
|
DYNAMIC_STRING ds_events_struct;
|
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_events_struct, NULL,
|
|
|
|
EVENTS_STRUCT_LEN, EVENTS_STRUCT_LEN))
|
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
if (run_query("show create table mysql.event",
|
|
|
|
&ds_events_struct, FALSE) ||
|
|
|
|
strstr(ds_events_struct.str, "IGNORE_BAD_TABLE_OPTIONS") != NULL)
|
|
|
|
ret= FALSE;
|
|
|
|
else
|
2018-11-07 12:16:29 +01:00
|
|
|
verbose("MariaDB upgrade detected");
|
2015-04-12 09:05:02 +02:00
|
|
|
|
|
|
|
dynstr_free(&ds_events_struct);
|
|
|
|
return(ret);
|
|
|
|
}
|
|
|
|
|
2015-04-12 07:56:21 +02:00
|
|
|
static int run_mysqlcheck_views(void)
|
|
|
|
{
|
2023-06-05 09:42:04 +02:00
|
|
|
const char *upgrade_views="--process-views=UPGRADE";
|
2015-05-04 22:00:24 +02:00
|
|
|
if (upgrade_from_mysql)
|
2015-04-12 09:21:02 +02:00
|
|
|
{
|
2015-05-04 22:00:24 +02:00
|
|
|
/*
|
|
|
|
this has to ignore opt_systables_only, because upgrade_from_mysql
|
|
|
|
is determined by analyzing systables. if we honor opt_systables_only
|
|
|
|
here, views won't be fixed by subsequent mysql_upgrade runs
|
|
|
|
*/
|
2015-04-28 21:24:32 +02:00
|
|
|
upgrade_views="--process-views=UPGRADE_FROM_MYSQL";
|
2015-05-04 22:00:24 +02:00
|
|
|
verbose("Phase %d/%d: Fixing views from mysql", ++phase, phases_total);
|
2015-04-12 09:21:02 +02:00
|
|
|
}
|
2015-04-14 05:26:22 +02:00
|
|
|
else if (opt_systables_only)
|
|
|
|
{
|
2015-05-04 22:00:24 +02:00
|
|
|
verbose("Phase %d/%d: Fixing views... Skipped", ++phase, phases_total);
|
2015-04-14 05:26:22 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2015-04-14 04:43:50 +02:00
|
|
|
else
|
2015-05-04 22:00:24 +02:00
|
|
|
verbose("Phase %d/%d: Fixing views", ++phase, phases_total);
|
2015-04-14 04:43:50 +02:00
|
|
|
|
2015-04-12 07:56:21 +02:00
|
|
|
print_conn_args("mysqlcheck");
|
|
|
|
return run_tool(mysqlcheck_path,
|
|
|
|
NULL, /* Send output from mysqlcheck directly to screen */
|
2015-12-08 10:16:41 +01:00
|
|
|
defaults_file,
|
2015-04-28 21:24:32 +02:00
|
|
|
"--all-databases", "--repair",
|
2015-04-14 04:43:50 +02:00
|
|
|
upgrade_views,
|
2015-04-28 21:24:32 +02:00
|
|
|
"--skip-process-tables",
|
2015-04-12 07:56:21 +02:00
|
|
|
opt_verbose ? "--verbose": "",
|
|
|
|
opt_silent ? "--silent": "",
|
2015-04-12 12:42:13 +02:00
|
|
|
opt_write_binlog ? "--write-binlog" : "--skip-write-binlog",
|
2015-04-12 07:56:21 +02:00
|
|
|
"2>&1",
|
|
|
|
NULL);
|
|
|
|
}
|
2008-12-09 09:30:49 +01:00
|
|
|
|
|
|
|
static int run_mysqlcheck_fixnames(void)
|
|
|
|
{
|
2015-04-28 21:24:32 +02:00
|
|
|
if (opt_systables_only)
|
|
|
|
{
|
|
|
|
verbose("Phase %d/%d: Fixing table and database names ... Skipped",
|
2015-05-04 22:00:24 +02:00
|
|
|
++phase, phases_total);
|
2015-04-28 21:24:32 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
verbose("Phase %d/%d: Fixing table and database names",
|
2015-05-04 22:00:24 +02:00
|
|
|
++phase, phases_total);
|
2009-05-27 10:24:25 +02:00
|
|
|
print_conn_args("mysqlcheck");
|
2008-12-09 09:30:49 +01:00
|
|
|
return run_tool(mysqlcheck_path,
|
|
|
|
NULL, /* Send output from mysqlcheck directly to screen */
|
2015-12-08 10:16:41 +01:00
|
|
|
defaults_file,
|
2008-12-09 09:30:49 +01:00
|
|
|
"--all-databases",
|
2008-06-15 15:01:07 +02:00
|
|
|
"--fix-db-names",
|
|
|
|
"--fix-table-names",
|
2014-08-14 14:38:08 +02:00
|
|
|
opt_verbose >= 1 ? "--verbose" : "",
|
|
|
|
opt_verbose >= 2 ? "--verbose" : "",
|
|
|
|
opt_verbose >= 3 ? "--verbose" : "",
|
2010-09-05 11:39:17 +02:00
|
|
|
opt_silent ? "--silent": "",
|
2009-09-28 08:24:19 +02:00
|
|
|
opt_write_binlog ? "--write-binlog" : "--skip-write-binlog",
|
2014-01-22 14:16:57 +01:00
|
|
|
"2>&1",
|
2007-04-18 13:21:39 +02:00
|
|
|
NULL);
|
|
|
|
}
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
static const char *expected_errors[]=
|
|
|
|
{
|
2018-11-24 14:13:41 +01:00
|
|
|
"ERROR 1051", /* Unknown table */
|
2007-04-18 13:21:39 +02:00
|
|
|
"ERROR 1060", /* Duplicate column name */
|
|
|
|
"ERROR 1061", /* Duplicate key name */
|
|
|
|
"ERROR 1054", /* Unknown column */
|
2018-11-24 14:13:41 +01:00
|
|
|
"ERROR 1146", /* Table does not exist */
|
2015-10-15 11:11:17 +02:00
|
|
|
"ERROR 1290", /* RR_OPTION_PREVENTS_STATEMENT */
|
2018-11-24 14:13:41 +01:00
|
|
|
"ERROR 1347", /* 'mysql.user' is not of type 'BASE TABLE' */
|
|
|
|
"ERROR 1348", /* Column 'Show_db_priv' is not updatable */
|
2020-07-23 18:57:40 +02:00
|
|
|
"ERROR 1356", /* definer of view lack rights (UPDATE) */
|
2022-03-23 20:17:32 +01:00
|
|
|
"ERROR 1449", /* definer ('mariadb.sys'@'localhost') of mysql.user does not exist */
|
2007-04-18 13:21:39 +02:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static my_bool is_expected_error(const char* line)
|
|
|
|
{
|
|
|
|
const char** error= expected_errors;
|
|
|
|
while (*error)
|
2007-01-18 17:38:05 +01:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Check if lines starting with ERROR
|
|
|
|
are in the list of expected errors
|
|
|
|
*/
|
|
|
|
if (strncmp(line, "ERROR", 5) != 0 ||
|
|
|
|
strncmp(line, *error, strlen(*error)) == 0)
|
|
|
|
return 1; /* Found expected error */
|
|
|
|
error++;
|
2007-01-18 17:38:05 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
static char* get_line(char* line)
|
|
|
|
{
|
|
|
|
while (*line && *line != '\n')
|
|
|
|
line++;
|
|
|
|
if (*line)
|
|
|
|
line++;
|
|
|
|
return line;
|
|
|
|
}
|
|
|
|
|
2017-03-04 17:17:00 +01:00
|
|
|
static my_bool from_before_10_1()
|
|
|
|
{
|
|
|
|
my_bool ret= TRUE;
|
|
|
|
DYNAMIC_STRING ds_events_struct;
|
|
|
|
|
|
|
|
if (upgrade_from_version[0])
|
|
|
|
{
|
|
|
|
return upgrade_from_version[1] == '.' ||
|
|
|
|
strncmp(upgrade_from_version, "10.1.", 5) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
|
|
|
dynstr_free(&ds_events_struct);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2023-06-05 09:42:04 +02:00
|
|
|
static int uninstall_plugins(void)
|
2021-01-20 21:59:51 +01:00
|
|
|
{
|
2023-06-05 09:42:04 +02:00
|
|
|
verbose("Phase %d/%d: uninstalling plugins", ++phase, phases_total);
|
2021-01-20 21:59:51 +01:00
|
|
|
if (ds_plugin_data_types.length)
|
|
|
|
{
|
|
|
|
char *plugins= ds_plugin_data_types.str;
|
|
|
|
char *next= get_line(plugins);
|
|
|
|
char buff[512];
|
|
|
|
while(*plugins)
|
|
|
|
{
|
|
|
|
if (next[-1] == '\n')
|
|
|
|
next[-1]= 0;
|
|
|
|
verbose("uninstalling plugin for %s data type", plugins);
|
|
|
|
strxnmov(buff, sizeof(buff)-1, "UNINSTALL SONAME ", plugins,"", NULL);
|
|
|
|
run_query(buff, NULL, TRUE);
|
|
|
|
plugins= next;
|
|
|
|
next= get_line(next);
|
|
|
|
}
|
|
|
|
}
|
2023-06-05 09:42:04 +02:00
|
|
|
return 0;
|
2021-01-20 21:59:51 +01:00
|
|
|
}
|
2023-06-05 09:42:04 +02:00
|
|
|
|
|
|
|
|
2021-01-20 21:59:51 +01:00
|
|
|
/**
|
|
|
|
@brief Install plugins for missing data types
|
|
|
|
@details Check for entries with "Unknown data type" in I_S.TABLES,
|
|
|
|
try to load plugins for these tables if available (MDEV-24093)
|
|
|
|
|
|
|
|
@return Operation status
|
|
|
|
@retval TRUE - error
|
|
|
|
@retval FALSE - success
|
|
|
|
*/
|
|
|
|
static int install_used_plugin_data_types(void)
|
|
|
|
{
|
|
|
|
DYNAMIC_STRING ds_result;
|
|
|
|
const char *query = "SELECT table_comment FROM information_schema.tables"
|
|
|
|
" WHERE table_comment LIKE 'Unknown data type: %'";
|
2023-10-17 15:41:52 +02:00
|
|
|
if (opt_systables_only)
|
|
|
|
return 0;
|
2021-01-20 21:59:51 +01:00
|
|
|
if (init_dynamic_string(&ds_result, "", 512, 512))
|
|
|
|
die("Out of memory");
|
|
|
|
run_query(query, &ds_result, TRUE);
|
|
|
|
|
|
|
|
if (ds_result.length)
|
|
|
|
{
|
|
|
|
char *line= ds_result.str;
|
|
|
|
char *next= get_line(line);
|
|
|
|
while(*line)
|
|
|
|
{
|
|
|
|
if (next[-1] == '\n')
|
|
|
|
next[-1]= 0;
|
|
|
|
if (strstr(line, "'MYSQL_JSON'"))
|
|
|
|
{
|
|
|
|
verbose("installing plugin for MYSQL_JSON data type");
|
|
|
|
if(!run_query("INSTALL SONAME 'type_mysql_json'", NULL, TRUE))
|
|
|
|
{
|
|
|
|
dynstr_append(&ds_plugin_data_types, "'type_mysql_json'");
|
|
|
|
dynstr_append(&ds_plugin_data_types, "\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "... can't %s\n", "INSTALL SONAME 'type_mysql_json'");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
line= next;
|
|
|
|
next= get_line(next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dynstr_free(&ds_result);
|
|
|
|
return 0;
|
|
|
|
}
|
2023-06-05 09:42:04 +02:00
|
|
|
|
|
|
|
|
2017-02-07 22:56:28 +01:00
|
|
|
/*
|
|
|
|
Check for entries with "Unknown storage engine" in I_S.TABLES,
|
|
|
|
try to load plugins for these tables if available (MDEV-11942)
|
|
|
|
*/
|
2017-03-04 17:17:00 +01:00
|
|
|
static int install_used_engines(void)
|
2017-02-07 22:56:28 +01:00
|
|
|
{
|
2017-03-04 17:17:00 +01:00
|
|
|
char buf[512];
|
2017-02-07 22:56:28 +01:00
|
|
|
DYNAMIC_STRING ds_result;
|
2017-11-07 09:06:15 +01:00
|
|
|
const char *query = "SELECT DISTINCT LOWER(engine) AS c1 FROM information_schema.tables"
|
|
|
|
" WHERE table_comment LIKE 'Unknown storage engine%'"
|
|
|
|
" ORDER BY c1";
|
2017-02-07 22:56:28 +01:00
|
|
|
|
2017-03-04 17:17:00 +01:00
|
|
|
if (opt_systables_only || !from_before_10_1())
|
|
|
|
{
|
|
|
|
verbose("Phase %d/%d: Installing used storage engines... Skipped", ++phase, phases_total);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
verbose("Phase %d/%d: Installing used storage engines", ++phase, phases_total);
|
2017-02-07 22:56:28 +01:00
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_result, "", 512, 512))
|
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
verbose("Checking for tables with unknown storage engine");
|
|
|
|
|
|
|
|
run_query(query, &ds_result, TRUE);
|
|
|
|
|
2017-03-04 17:17:00 +01:00
|
|
|
if (ds_result.length)
|
2017-02-07 22:56:28 +01:00
|
|
|
{
|
2017-03-04 17:17:00 +01:00
|
|
|
char *line= ds_result.str, *next=get_line(line);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (next[-1] == '\n')
|
|
|
|
next[-1]=0;
|
2017-02-07 22:56:28 +01:00
|
|
|
|
2017-03-04 17:17:00 +01:00
|
|
|
verbose("installing plugin for '%s' storage engine", line);
|
2017-02-07 22:56:28 +01:00
|
|
|
|
2017-03-04 17:17:00 +01:00
|
|
|
// we simply assume soname=ha_enginename
|
|
|
|
strxnmov(buf, sizeof(buf)-1, "install soname 'ha_", line, "'", NULL);
|
|
|
|
|
|
|
|
|
|
|
|
if (run_query(buf, NULL, TRUE))
|
|
|
|
fprintf(stderr, "... can't %s\n", buf);
|
|
|
|
line=next;
|
|
|
|
next=get_line(line);
|
|
|
|
} while (*line);
|
2017-02-07 22:56:28 +01:00
|
|
|
}
|
2017-03-04 17:17:00 +01:00
|
|
|
dynstr_free(&ds_result);
|
|
|
|
return 0;
|
2017-02-07 22:56:28 +01:00
|
|
|
}
|
|
|
|
|
2023-06-05 09:42:04 +02:00
|
|
|
|
2020-03-10 11:24:55 +01:00
|
|
|
static int check_slave_repositories(void)
|
|
|
|
{
|
|
|
|
DYNAMIC_STRING ds_result;
|
|
|
|
int row_count= 0;
|
|
|
|
int error= 0;
|
|
|
|
const char *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");
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2017-02-07 22:56:28 +01:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
2022-01-04 19:09:40 +01:00
|
|
|
Update all system tables in MariaDB Server to current
|
2007-04-18 13:21:39 +02:00
|
|
|
version using "mysql" to execute all the SQL commands
|
|
|
|
compiled into the mysql_fix_privilege_tables array
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int run_sql_fix_privilege_tables(void)
|
|
|
|
{
|
2024-06-15 13:26:07 +02:00
|
|
|
int found_real_errors= 0, query_started= 0;
|
2012-08-01 16:27:34 +02:00
|
|
|
const char **query_ptr;
|
2024-06-15 13:26:07 +02:00
|
|
|
const char *end;
|
2012-08-01 16:27:34 +02:00
|
|
|
DYNAMIC_STRING ds_script;
|
2007-04-18 13:21:39 +02:00
|
|
|
DYNAMIC_STRING ds_result;
|
2024-06-15 13:26:07 +02:00
|
|
|
DYNAMIC_STRING ds_query;
|
2007-04-18 13:21:39 +02:00
|
|
|
DBUG_ENTER("run_sql_fix_privilege_tables");
|
|
|
|
|
2024-06-15 13:26:07 +02:00
|
|
|
if (init_dynamic_string(&ds_script, "", 96*1024, 8196))
|
2012-08-01 16:27:34 +02:00
|
|
|
die("Out of memory");
|
|
|
|
|
2024-06-15 13:26:07 +02:00
|
|
|
if (init_dynamic_string(&ds_result, "", 1024, 1024))
|
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
if (init_dynamic_string(&ds_query, "", 1024, 1024))
|
2007-04-18 13:21:39 +02:00
|
|
|
die("Out of memory");
|
|
|
|
|
2015-04-28 21:24:32 +02:00
|
|
|
verbose("Phase %d/%d: Running 'mysql_fix_privilege_tables'",
|
2015-05-04 22:00:24 +02:00
|
|
|
++phase, phases_total);
|
|
|
|
|
2012-08-01 16:27:34 +02:00
|
|
|
/*
|
|
|
|
Individual queries can not be executed independently by invoking
|
|
|
|
a forked mysql client, because the script uses session variables
|
|
|
|
and prepared statements.
|
|
|
|
*/
|
2022-12-12 04:20:08 +01:00
|
|
|
for ( query_ptr= &mariadb_fix_privilege_tables[0];
|
2012-08-01 16:27:34 +02:00
|
|
|
*query_ptr != NULL;
|
|
|
|
query_ptr++
|
|
|
|
)
|
|
|
|
{
|
2014-11-19 00:19:17 +01:00
|
|
|
if (strcasecmp(*query_ptr, "flush privileges;\n"))
|
|
|
|
dynstr_append(&ds_script, *query_ptr);
|
2012-08-01 16:27:34 +02:00
|
|
|
}
|
|
|
|
|
2023-03-06 18:32:03 +01:00
|
|
|
run_query(ds_script.str, (opt_verbose >= 5) ? NULL : &ds_result, TRUE);
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2006-04-28 06:07:25 +02:00
|
|
|
{
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
|
|
|
Scan each line of the result for real errors
|
|
|
|
and ignore the expected one(s) like "Duplicate column name",
|
|
|
|
"Unknown column" and "Duplicate key name" since they just
|
|
|
|
indicate the system tables are already up to date
|
|
|
|
*/
|
2024-06-15 13:26:07 +02:00
|
|
|
const char *line= ds_result.str;
|
2007-04-18 13:21:39 +02:00
|
|
|
do
|
|
|
|
{
|
2024-06-15 13:26:07 +02:00
|
|
|
size_t length;
|
|
|
|
end= strchr(line, '\n');
|
|
|
|
if (!end)
|
|
|
|
end= strend(line);
|
|
|
|
else
|
|
|
|
end++; /* Include end \n */
|
|
|
|
length= (size_t) (end - line);
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
if (!is_expected_error(line))
|
|
|
|
{
|
|
|
|
/* Something unexpected failed, dump error line to screen */
|
|
|
|
found_real_errors++;
|
2024-06-15 13:26:07 +02:00
|
|
|
if (ds_query.length)
|
|
|
|
fwrite(ds_query.str, sizeof(char), ds_query.length, stderr);
|
|
|
|
fwrite(line, sizeof(char), length, stderr);
|
|
|
|
query_started= 0;
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
2009-12-03 17:15:47 +01:00
|
|
|
else if (strncmp(line, "WARNING", 7) == 0)
|
|
|
|
{
|
2024-06-15 13:26:07 +02:00
|
|
|
fwrite(line, sizeof(char), length, stderr);
|
|
|
|
query_started= 0;
|
2009-12-03 17:15:47 +01:00
|
|
|
}
|
2024-06-15 13:26:07 +02:00
|
|
|
else if (!strncmp(line, "--------------\n", 16))
|
|
|
|
{
|
|
|
|
/* mariadb separates query from the error with a line of '-' */
|
|
|
|
if (!query_started++)
|
|
|
|
ds_query.length= 0; /* Truncate */
|
|
|
|
else
|
|
|
|
query_started= 0; /* End of query */
|
|
|
|
}
|
|
|
|
else if (query_started)
|
|
|
|
{
|
|
|
|
dynstr_append_mem(&ds_query, line, length);
|
|
|
|
}
|
|
|
|
} while (*(line= end));
|
2006-04-28 06:07:25 +02:00
|
|
|
}
|
2024-06-15 13:26:07 +02:00
|
|
|
dynstr_free(&ds_query);
|
2007-04-18 13:21:39 +02:00
|
|
|
dynstr_free(&ds_result);
|
2012-08-01 16:27:34 +02:00
|
|
|
dynstr_free(&ds_script);
|
2011-07-10 20:09:17 +02:00
|
|
|
DBUG_RETURN(found_real_errors);
|
2007-04-18 13:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-05 09:42:04 +02:00
|
|
|
static int flush_privileges(void)
|
|
|
|
{
|
|
|
|
verbose("Phase %d/%d: Running 'FLUSH PRIVILEGES'", ++phase, phases_total);
|
|
|
|
return run_query("FLUSH PRIVILEGES", NULL, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-21 18:21:40 +01:00
|
|
|
/**
|
|
|
|
Check if the server version matches with the server version mysql_upgrade
|
|
|
|
was compiled with.
|
|
|
|
|
|
|
|
@return 0 match successful
|
|
|
|
1 failed
|
|
|
|
*/
|
|
|
|
static int check_version_match(void)
|
|
|
|
{
|
|
|
|
DYNAMIC_STRING ds_version;
|
|
|
|
char version_str[NAME_CHAR_LEN + 1];
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
2014-01-22 14:16:57 +01:00
|
|
|
print_error("Version check failed. Got the following error when calling "
|
2020-09-25 14:58:08 +02:00
|
|
|
"the 'mysql' command line client", &ds_version);
|
2013-03-21 18:21:40 +01:00
|
|
|
dynstr_free(&ds_version);
|
|
|
|
return 1; /* Query failed */
|
|
|
|
}
|
|
|
|
|
|
|
|
dynstr_free(&ds_version);
|
|
|
|
|
|
|
|
if (calc_server_version((char *) version_str) != MYSQL_VERSION_ID)
|
|
|
|
{
|
2023-06-05 09:42:04 +02:00
|
|
|
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);
|
2013-03-21 18:21:40 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2022-01-04 19:09:40 +01:00
|
|
|
return 0;
|
2013-03-21 18:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2017-05-17 15:16:24 +02:00
|
|
|
char self_name[FN_REFLEN + 1];
|
2008-08-07 18:24:39 +02:00
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
MY_INIT(argv[0]);
|
2022-01-04 19:09:40 +01:00
|
|
|
DBUG_PROCESS(argv[0]);
|
|
|
|
|
2018-03-16 13:35:42 +01:00
|
|
|
load_defaults_or_exit("my", load_default_groups, &argc, &argv);
|
|
|
|
defaults_argv= argv; /* Must be freed by 'free_defaults' */
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2021-06-06 13:21:03 +02:00
|
|
|
#if defined(_WIN32)
|
2008-08-07 18:24:39 +02:00
|
|
|
if (GetModuleFileName(NULL, self_name, FN_REFLEN) == 0)
|
|
|
|
#endif
|
|
|
|
{
|
2017-05-17 15:16:24 +02:00
|
|
|
strmake_buf(self_name, argv[0]);
|
2008-08-07 18:24:39 +02:00
|
|
|
}
|
|
|
|
|
2009-05-27 10:24:25 +02:00
|
|
|
if (init_dynamic_string(&ds_args, "", 512, 256) ||
|
2021-01-20 21:59:51 +01:00
|
|
|
init_dynamic_string(&conn_args, "", 512, 256) ||
|
|
|
|
init_dynamic_string(&ds_plugin_data_types, "", 512, 256))
|
2007-04-18 13:21:39 +02:00
|
|
|
die("Out of memory");
|
|
|
|
|
|
|
|
if (handle_options(&argc, &argv, my_long_options, get_one_option))
|
|
|
|
die(NULL);
|
2007-08-01 21:59:05 +02:00
|
|
|
if (debug_info_flag)
|
|
|
|
my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
|
|
|
|
if (debug_check_flag)
|
|
|
|
my_end_arg= MY_CHECK_ERROR;
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
if (tty_password)
|
2007-01-18 17:38:05 +01:00
|
|
|
{
|
2023-06-12 22:16:49 +02:00
|
|
|
opt_password= my_get_tty_password(NullS);
|
2007-04-18 13:21:39 +02:00
|
|
|
/* add password to defaults file */
|
2022-02-10 11:28:46 +01:00
|
|
|
add_one_option_cnf_file(&ds_args, "password", opt_password);
|
2007-01-18 17:38:05 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
/* add user to defaults file */
|
2022-02-10 11:28:46 +01:00
|
|
|
add_one_option_cnf_file(&ds_args, "user", opt_user);
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2015-12-08 10:16:41 +01:00
|
|
|
cnf_file_path= strmov(defaults_file, "--defaults-file=");
|
|
|
|
{
|
|
|
|
int fd= create_temp_file(cnf_file_path, opt_tmpdir[0] ? opt_tmpdir : NULL,
|
2018-05-17 22:53:57 +02:00
|
|
|
"mysql_upgrade-", 0, MYF(MY_FAE));
|
2017-05-24 13:11:33 +02:00
|
|
|
if (fd < 0)
|
|
|
|
die(NULL);
|
2015-12-08 10:16:41 +01:00
|
|
|
my_write(fd, USTRING_WITH_LEN( "[client]\n"), MYF(MY_FAE));
|
|
|
|
my_write(fd, (uchar*)ds_args.str, ds_args.length, MYF(MY_FAE));
|
2022-01-04 19:09:40 +01:00
|
|
|
my_close(fd, MYF(MY_WME));
|
2015-12-08 10:16:41 +01:00
|
|
|
}
|
2007-04-18 13:21:39 +02:00
|
|
|
|
|
|
|
/* Find mysql */
|
2022-09-28 16:20:23 +02:00
|
|
|
find_tool(mysql_path, IF_WIN("mariadb.exe", "mariadb"), self_name);
|
2007-04-18 13:21:39 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
open_mysql_upgrade_file();
|
|
|
|
|
|
|
|
if (opt_check_upgrade)
|
2023-12-17 06:54:01 +01:00
|
|
|
{
|
|
|
|
int upgrade_needed = upgrade_already_done(0);
|
|
|
|
free_used_memory();
|
|
|
|
my_end(my_end_arg);
|
|
|
|
exit(upgrade_needed == 0);
|
|
|
|
}
|
2022-01-04 19:09:40 +01:00
|
|
|
|
2014-08-06 13:27:44 +02:00
|
|
|
/* Find mysqlcheck */
|
2022-09-28 16:20:23 +02:00
|
|
|
find_tool(mysqlcheck_path, IF_WIN("mariadb-check.exe", "mariadb-check"), self_name);
|
2014-08-06 13:27:44 +02:00
|
|
|
|
|
|
|
if (opt_systables_only && !opt_silent)
|
|
|
|
printf("The --upgrade-system-tables option was used, user tables won't be touched.\n");
|
|
|
|
|
2007-04-18 13:21:39 +02:00
|
|
|
/*
|
2023-01-31 22:13:41 +01:00
|
|
|
Read the mariadb_upgrade_info file to check if mysql_upgrade
|
2022-01-04 19:09:40 +01:00
|
|
|
already has been run for this installation of MariaDB
|
2007-04-18 13:21:39 +02:00
|
|
|
*/
|
2022-01-04 19:09:40 +01:00
|
|
|
if (!opt_force && !upgrade_already_done(0))
|
|
|
|
goto end; /* Upgrade already done */
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2013-03-21 18:21:40 +01:00
|
|
|
if (opt_version_check && check_version_match())
|
|
|
|
die("Upgrade failed");
|
|
|
|
|
2015-05-04 22:00:24 +02:00
|
|
|
upgrade_from_mysql= is_mysql();
|
|
|
|
|
2007-02-28 21:05:39 +01:00
|
|
|
/*
|
2007-04-18 13:21:39 +02:00
|
|
|
Run "mysqlcheck" and "mysql_fix_privilege_tables.sql"
|
2007-02-28 21:05:39 +01:00
|
|
|
*/
|
2017-03-04 17:17:00 +01:00
|
|
|
if (run_mysqlcheck_upgrade(TRUE) ||
|
|
|
|
install_used_engines() ||
|
2021-01-20 21:59:51 +01:00
|
|
|
install_used_plugin_data_types() ||
|
2015-05-04 22:00:24 +02:00
|
|
|
run_sql_fix_privilege_tables() ||
|
2023-06-05 09:42:04 +02:00
|
|
|
run_mysqlcheck_views() ||
|
2015-05-04 22:00:24 +02:00
|
|
|
run_mysqlcheck_fixnames() ||
|
2020-03-10 11:24:55 +01:00
|
|
|
run_mysqlcheck_upgrade(FALSE) ||
|
2023-06-05 09:42:04 +02:00
|
|
|
check_slave_repositories() ||
|
|
|
|
uninstall_plugins() ||
|
|
|
|
flush_privileges())
|
2007-04-18 13:21:39 +02:00
|
|
|
die("Upgrade failed" );
|
|
|
|
verbose("OK");
|
2006-04-28 06:07:25 +02:00
|
|
|
|
2022-01-04 19:09:40 +01:00
|
|
|
/* Finish writing indicating upgrade has been performed */
|
2023-01-31 22:13:41 +01:00
|
|
|
finish_mariadb_upgrade_info_file();
|
2007-02-28 21:05:39 +01:00
|
|
|
|
2015-05-04 22:00:24 +02:00
|
|
|
DBUG_ASSERT(phase == phases_total);
|
|
|
|
|
2015-07-31 11:13:39 +02:00
|
|
|
end:
|
2023-03-06 18:32:03 +01:00
|
|
|
print_conn_args("mariadb-check");
|
2007-04-18 13:21:39 +02:00
|
|
|
free_used_memory();
|
2007-08-01 21:59:05 +02:00
|
|
|
my_end(my_end_arg);
|
2007-04-18 13:21:39 +02:00
|
|
|
exit(0);
|
2006-11-08 03:45:50 +01:00
|
|
|
}
|