Commit cf3487ac authored by unknown's avatar unknown

BUG#20100 fix: mysql_upgrade modified to also accept all

the communication parameters from the command line
and pass 'em correctly to both mysqlcheck and mysql


client/mysql_upgrade.c:
  Now mysql_upgrade passes all the parameters specified on 
  the command line to both mysqlcheck and mysql through 
  the upgrade_defaults file
parent 03618c71
...@@ -16,21 +16,42 @@ ...@@ -16,21 +16,42 @@
#include "client_priv.h" #include "client_priv.h"
#include <my_dir.h> #include <my_dir.h>
#include <my_list.h>
#include <sslopt-vars.h>
#define UPGRADE_DEFAULTS_NAME "mysql_upgrade_defaults"
#define MYSQL_UPGRADE_INFO_NAME "mysql_upgrade_info"
#define MYSQL_FIX_PRIV_TABLES_NAME "mysql_fix_privilege_tables.sql"
#define MY_PARENT (1 << 0)
#define MY_ISDIR (1 << 1)
#define MY_SEARCH_SELF (1 << 2)
#ifdef __WIN__ #ifdef __WIN__
const char *mysqlcheck_name= "mysqlcheck.exe"; const char *mysqlcheck_name= "mysqlcheck.exe";
const char *mysql_name= "mysql.exe"; const char *mysql_name= "mysql.exe";
const char *mysqld_name= "mysqld.exe";
#else #else
const char *mysqlcheck_name= "mysqlcheck"; const char *mysqlcheck_name= "mysqlcheck";
const char *mysql_name= "mysql"; const char *mysql_name= "mysql";
const char *mysqld_name= "mysqld";
#endif /*__WIN__*/ #endif /*__WIN__*/
static my_bool opt_force= 0, opt_verbose= 0, tty_password= 0; extern TYPELIB sql_protocol_typelib;
static my_bool opt_force= 0, opt_verbose= 0, opt_compress= 0;
static char *user= (char*) "root", *basedir= 0, *datadir= 0, *opt_password= 0; static char *user= (char*) "root", *basedir= 0, *datadir= 0, *opt_password= 0;
static my_bool upgrade_defaults_created= 0; static char *current_host= 0;
static my_string opt_mysql_port, opt_mysql_unix_port= 0; static char *opt_default_charset= 0, *opt_charsets_dir= 0;
static char *default_dbug_option= (char*) "d:t:O,/tmp/comp_err.trace"; #ifdef HAVE_SMEM
static my_bool info_flag= 0; static char *shared_memory_base_name= 0;
#endif
static char *opt_protocol= 0;
static my_string opt_mysql_port= 0, opt_mysql_unix_port= 0;
#ifndef DBUG_OFF
static char *default_dbug_option= (char*) "d:t:O,/tmp/mysql_upgrade.trace";
#endif
static my_bool info_flag= 0, tty_password= 0;
static struct my_option my_long_options[]= static struct my_option my_long_options[]=
{ {
...@@ -50,27 +71,51 @@ static struct my_option my_long_options[]= ...@@ -50,27 +71,51 @@ static struct my_option my_long_options[]=
#endif #endif
{"debug-info", 'T', "Print some debug info at exit.", (gptr *) & info_flag, {"debug-info", 'T', "Print some debug info at exit.", (gptr *) & info_flag,
(gptr *) & info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, (gptr *) & info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{"force", 'f', "Continue even if we get an sql-error.", {"default-character-set", OPT_DEFAULT_CHARSET,
"Set the default character set.", (gptr*) &opt_default_charset,
(gptr*) &opt_default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"force", 'f', "Force execution of mysqlcheck even if mysql_upgrade "
"has already been executed for the current version of MySQL.",
(gptr*) &opt_force, (gptr*) &opt_force, 0, GET_BOOL, NO_ARG, 0, 0, (gptr*) &opt_force, (gptr*) &opt_force, 0, GET_BOOL, NO_ARG, 0, 0,
0, 0, 0, 0}, 0, 0, 0, 0},
{"character-sets-dir", OPT_CHARSETS_DIR,
"Directory where character sets are.", (gptr*) &opt_charsets_dir,
(gptr*) &opt_charsets_dir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"compress", OPT_COMPRESS, "Use compression in server/client protocol.",
(gptr*) &opt_compress, (gptr*) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
0, 0, 0},
{"host",'h', "Connect to host.", (gptr*) &current_host,
(gptr*) &current_host, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"password", 'p', {"password", 'p',
"Password to use when connecting to server. If password is not given it's solicited on the tty.", "Password to use when connecting to server. If password is not given"
0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, " it's solicited on the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#ifdef __WIN__
{"pipe", 'W', "Use named pipes to connect to server.", 0, 0, 0,
GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port, {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
(gptr*) &opt_mysql_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, (gptr*) &opt_mysql_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
0},
{"protocol", OPT_MYSQL_PROTOCOL, {"protocol", OPT_MYSQL_PROTOCOL,
"The protocol of connection (tcp,socket,pipe,memory).", "The protocol of connection (tcp,socket,pipe,memory).",
0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifdef HAVE_SMEM
{"shared-memory-base-name", OPT_SHARED_MEMORY_BASE_NAME,
"Base name of shared memory.", (gptr*) &shared_memory_base_name,
(gptr*) &shared_memory_base_name, 0,
GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#endif
{"socket", 'S', "Socket file to use for connection.", {"socket", 'S', "Socket file to use for connection.",
(gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, GET_STR, (gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0,
REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"user", 'u', "User for login if not current user.", (gptr*) &user, {"user", 'u', "User for login if not current user.", (gptr*) &user,
(gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
{"verbose", 'v', "Display more output about the process", (gptr*) &opt_verbose, #include <sslopt-longopts.h>
(gptr *) &opt_verbose, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0}, {"verbose", 'v', "Display more output about the process",
(gptr*) &opt_verbose, (gptr*) &opt_verbose, 0,
GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
}; };
static const char *load_default_groups[]= static const char *load_default_groups[]=
{ {
"mysql_upgrade", 0 "mysql_upgrade", 0
...@@ -78,6 +123,81 @@ static const char *load_default_groups[]= ...@@ -78,6 +123,81 @@ static const char *load_default_groups[]=
#include <help_end.h> #include <help_end.h>
static LIST *extra_defaults= NULL;
typedef struct _extra_default
{
int id;
const char *name;
int n_len;
const char *value;
int v_len;
} extra_default_t;
static inline
void set_extra_default(int id, const struct my_option *opt)
{
switch (id) {
case 'b': case 'd': /* these are ours */
case 'f': /* --force is ours */
case 'u': /* --user passed on cmdline */
case 'T': /* --debug-info is not accepted by mysqlcheck */
/* so, do nothing */
break;
default:
{
LIST *l;
extra_default_t *d;
/*
Remove any earlier duplicates: they can
refer to invalid memory addresses (stale pointers)
*/
l= extra_defaults;
while (l)
{
LIST *n= l->next;
d= l->data;
if (d->id == id)
{
extra_defaults= list_delete(extra_defaults, l);
my_free((gptr)l, MYF(0));
my_free((gptr)d, MYF(0));
}
l= n;
}
d= (extra_default_t *)my_malloc(sizeof(extra_default_t),
MYF(MY_FAE|MY_ZEROFILL));
d->id= id;
d->name= opt->name;
d->n_len= strlen(opt->name);
if (opt->arg_type != NO_ARG)
switch (opt->var_type & GET_TYPE_MASK) {
case GET_BOOL:
if (*((int *)opt->value))
{
d->value= "true";
d->v_len= 4;
}
break;
case GET_STR:
case GET_STR_ALLOC:
d->value= *opt->value;
d->v_len= strlen(d->value);
break;
default:
my_printf_error(0, "Error: internal error at %s:%d", MYF(0),
__FILE__, __LINE__);
exit(1);
}
list_push(extra_defaults, d);
}
}
}
static my_bool static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)), get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
char *argument) char *argument)
...@@ -85,16 +205,13 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)), ...@@ -85,16 +205,13 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
switch (optid) { switch (optid) {
case '?': case '?':
puts puts
("MySQL utility script to upgrade database to the current server version"); ("MySQL utility to upgrade database to the current server version");
puts(""); puts("");
my_print_help(my_long_options); my_print_help(my_long_options);
exit(0); exit(0);
case '#': case '#':
DBUG_PUSH(argument ? argument : default_dbug_option); DBUG_PUSH(argument ? argument : default_dbug_option);
break; break;
case 'f':
opt_force= TRUE;
break;
case 'p': case 'p':
tty_password= 1; tty_password= 1;
if (argument) if (argument)
...@@ -109,315 +226,416 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)), ...@@ -109,315 +226,416 @@ get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
tty_password= 0; tty_password= 0;
} }
break; break;
#ifdef __WIN__
case 'W':
my_free(opt_protocol, MYF(MY_ALLOW_ZERO_PTR));
opt_protocol= my_strdup("pipe", MYF(MY_FAE));
break;
#endif
case OPT_MYSQL_PROTOCOL:
if (find_type(argument, &sql_protocol_typelib, 0) > 0)
{
my_free(opt_protocol, MYF(MY_ALLOW_ZERO_PTR));
opt_protocol= my_strdup(argument, MYF(MY_FAE));
}
else
{
fprintf(stderr, "Unknown option to protocol: %s\n", argument);
exit(1);
}
break;
#include <sslopt-case.h>
default:; default:;
}; }
set_extra_default(opt->id, opt);
return 0; return 0;
} }
/* buffer should be not smaller than FN_REFLEN */
static my_bool test_file_exists_res(const char *dir, const char *fname,
char *buffer, char **buf_end)
{
MY_STAT stat_info;
*buf_end= strxnmov(buffer, FN_REFLEN-1, dir, "/", fname, NullS);
unpack_filename(buffer, buffer);
return my_stat(buffer, &stat_info, MYF(0)) != 0;
}
static my_bool test_file_exists(const char *dir, const char *fname)
{
char path[FN_REFLEN];
char *path_end;
return test_file_exists_res(dir, fname, path, &path_end);
}
static int create_check_file(const char *path) static int create_check_file(const char *path)
{ {
File check_file= my_open(path, O_CREAT | O_WRONLY, MYF(MY_FAE | MY_WME)); int ret;
int error; File fd;
if (check_file < 0) fd= my_open(path, O_CREAT | O_WRONLY, MYF(MY_FAE | MY_WME));
return 1; if (fd < 0) {
ret= 1;
error= my_write(check_file, goto error;
MYSQL_SERVER_VERSION, strlen(MYSQL_SERVER_VERSION), }
ret= my_write(fd, MYSQL_SERVER_VERSION,
sizeof(MYSQL_SERVER_VERSION) - 1,
MYF(MY_WME | MY_FNABP)); MYF(MY_WME | MY_FNABP));
error= my_close(check_file, MYF(MY_FAE | MY_WME)) || error; ret|= my_close(fd, MYF(MY_FAE | MY_WME));
return error; error:
return ret;
} }
static int create_defaults_file(const char *path, const char *our_defaults_path) static int create_defaults_file(const char *path, const char *forced_path)
{ {
uint b_read; int ret;
File our_defaults_file, defaults_file; uint cnt;
char buffer[512]; File forced_file, defaults_file;
char *buffer_end;
int failed_to_open_count= 0; DYNAMIC_STRING buf;
int error; extra_default_t *d;
/* check if the defaults file is needed at all */ my_delete(path, MYF(0));
if (!opt_password)
return 0;
retry_open:
defaults_file= my_open(path, O_BINARY | O_CREAT | O_WRONLY | O_EXCL, defaults_file= my_open(path, O_BINARY | O_CREAT | O_WRONLY | O_EXCL,
MYF(MY_FAE | MY_WME)); MYF(MY_FAE | MY_WME));
if (defaults_file < 0) if (defaults_file < 0)
{ {
if (failed_to_open_count == 0) ret= 1;
{ goto out;
remove(path); }
failed_to_open_count+= 1;
goto retry_open; if (init_dynamic_string(&buf, NULL, my_getpagesize(), FN_REFLEN))
} {
else ret= 1;
return 1; goto error;
} }
upgrade_defaults_created= 1; if (forced_path)
if (our_defaults_path)
{ {
our_defaults_file= my_open(our_defaults_path, O_RDONLY, forced_file= my_open(forced_path, O_RDONLY, MYF(MY_FAE | MY_WME));
MYF(MY_FAE | MY_WME)); if (forced_file < 0)
if (our_defaults_file < 0) {
return 1; ret= 1;
goto error;
}
do do
{ {
if (((b_read= my_read(our_defaults_file, buffer, cnt= my_read(forced_file, buf.str, buf.max_length, MYF(MY_WME));
sizeof(buffer), MYF(MY_WME))) == MY_FILE_ERROR) || if ((cnt == MY_FILE_ERROR)
my_write(defaults_file, buffer, b_read, MYF(MY_FNABP | MY_WME))) || my_write(defaults_file, buf.str, cnt, MYF(MY_FNABP | MY_WME)))
{ {
error= 1; ret= 1;
goto close_return; my_close(forced_file, MYF(0));
goto error;
} }
} while (b_read == sizeof(buffer)); } while (cnt == buf.max_length);
my_close(forced_file, MYF(0));
} }
buffer_end= strnmov(buffer, "\n[client]", sizeof(buffer));
if (opt_password) dynstr_set(&buf, "\n[client]");
buffer_end= strxnmov(buffer_end, sizeof(buffer), while (extra_defaults)
"\npassword=", opt_password, NullS); {
error= my_write(defaults_file, buffer, (int) (buffer_end - buffer), int len;
MYF(MY_WME | MY_FNABP));
close_return: d= extra_defaults->data;
return my_close(defaults_file, MYF(MY_WME)) || error; len= d->n_len + d->v_len + 1;
if (buf.length + len >= buf.max_length) /* to avoid realloc() */
{
if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME)))
{
ret= 1;
goto error;
}
dynstr_set(&buf, NULL);
}
if (dynstr_append_mem(&buf, "\n", 1)
|| dynstr_append_mem(&buf, d->name, d->n_len)
|| (d->v_len && (dynstr_append_mem(&buf, "=", 1)
|| dynstr_append_mem(&buf, d->value, d->v_len))))
{
ret= 1;
goto error;
}
my_delete((gptr)d, MYF(0));
list_pop(extra_defaults); /* pop off the head */
}
if (my_write(defaults_file, buf.str, buf.length, MYF(MY_FNABP | MY_WME)))
{
ret= 1;
goto error;
}
/* everything's all right */
ret= 0;
error:
dynstr_free(&buf);
if (defaults_file >= 0)
ret|= my_close(defaults_file, MYF(MY_WME));
if (ret)
my_delete(path, MYF(0));
out:
return ret;
}
/* Compare filenames */
static int comp_names(struct fileinfo *a, struct fileinfo *b)
{
return (strcmp(a->name,b->name));
}
static int
find_file(const char *name, const char *root, uint flags, char *result, size_t len, ...)
{
int ret;
va_list va;
FILEINFO key= { name };
const char *subdir;
char *cp;
DBUG_ASSERT(root != NULL);
cp= strmake(result, root, len);
if (cp[-1] != FN_LIBCHAR)
*cp= FN_LIBCHAR;
ret= 1;
va_start(va, len);
subdir= (!(flags & MY_SEARCH_SELF)) ? va_arg(va, char *) : "";
while (ret && subdir)
{
MY_DIR *dir;
FILEINFO *match;
uint i;
char *cp1;
cp1= strnmov(cp + 1, subdir, len - (cp - result) - 1);
dir= my_dir(result, (flags & MY_ISDIR) ? MY_WANT_STAT : MYF(0));
if (dir)
{
match= bsearch(&key, dir->dir_entry, dir->number_off_files,
sizeof(FILEINFO), (qsort_cmp)comp_names);
if (match)
{
if (!(flags & MY_PARENT))
{
if (cp1[-1] != FN_LIBCHAR)
*cp1++= FN_LIBCHAR;
strnmov(cp1, name, len - (cp1 - result));
}
else
{
if (cp1[-1] == FN_LIBCHAR)
--cp1;
while (*--cp1 == FN_LIBCHAR)
{}
*++cp1= FN_LIBCHAR;
*++cp1= '\0';
}
if (flags & MY_ISDIR)
ret= !MY_S_ISDIR(match->mystat->st_mode);
else
ret= 0;
}
my_dirend(dir);
}
subdir= va_arg(va, char *);
}
va_end(va);
return ret;
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char bindir[FN_REFLEN]; int ret;
char *bindir_end, *buf_end;
char datadir_buf[FN_REFLEN];
char mysqlcheck_line[FN_REFLEN], *mysqlcheck_end;
char check_file_name[FN_REFLEN];
int check_file;
char fix_priv_tables_cmd[FN_REFLEN], *fix_cmd_end;
char script_line[FN_REFLEN];
int error;
char *forced_defaults_file; char *forced_defaults_file;
char *forced_extra_defaults; char *forced_extra_defaults;
char *defaults_group_suffix; char *defaults_group_suffix;
char upgrade_defaults_path[FN_REFLEN], *defaults_to_use= 0; const char *script_line;
char port_socket[100], *port_socket_end; char *upgrade_defaults_path;
char *defaults_to_use= NULL;
int upgrade_defaults_created= 0;
char path[FN_REFLEN];
DYNAMIC_STRING cmdline;
MY_INIT(argv[0]); MY_INIT(argv[0]);
#ifdef __NETWARE__ #ifdef __NETWARE__
setscreenmode(SCR_AUTOCLOSE_ON_EXIT); setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
#endif #endif
/* Check if we are forced to use specific defaults */
get_defaults_options(argc, argv,
&forced_defaults_file, &forced_extra_defaults,
&defaults_group_suffix);
load_defaults("my", load_default_groups, &argc, &argv); load_defaults("my", load_default_groups, &argc, &argv);
if ((error= handle_options(&argc, &argv, my_long_options, get_one_option))) if (handle_options(&argc, &argv, my_long_options, get_one_option))
exit(error); {
ret= 1;
goto error;
}
if (tty_password) if (tty_password)
opt_password= get_tty_password(NullS); opt_password= get_tty_password(NullS);
/* Check if we want to force the use a specific default file */ if (init_dynamic_string(&cmdline, NULL, 2 * FN_REFLEN + 128, FN_REFLEN))
get_defaults_options(argc, argv,
&forced_defaults_file, &forced_extra_defaults,
&defaults_group_suffix);
port_socket_end= port_socket;
if (opt_mysql_port)
port_socket_end= strxnmov(port_socket, sizeof(port_socket) - 1, " --port=",
opt_mysql_port, NullS);
if (opt_mysql_unix_port)
port_socket_end= strxnmov(port_socket_end,
sizeof(port_socket) -
(int)(port_socket_end - port_socket) - 1,
" --socket=", opt_mysql_unix_port, NullS);
*port_socket_end= 0;
if (basedir)
{ {
bindir_end= strmake(bindir, basedir, sizeof(bindir)-1); ret= 1;
goto error;
} }
else if (!basedir)
{ {
if (test_file_exists("./share/mysql/english", "errmsg.sys") my_getwd(path, sizeof(path), MYF(0));
&& (test_file_exists("./bin", "mysqld") || basedir= my_strdup(path, MYF(0));
test_file_exists("./libexec", "mysqld"))) if (find_file("errmsg.sys", basedir, MYF(0), path, sizeof(path),
{ "share/mysql/english", NullS)
my_getwd(bindir, sizeof(bindir), MYF(0)); || find_file(mysqld_name, basedir, MYF(0), path, sizeof(path),
bindir_end= bindir + strlen(bindir); "bin", "libexec", NullS))
}
else
{ {
bindir_end= strmake(bindir, DEFAULT_MYSQL_HOME, sizeof(bindir)-1); my_strdup((gptr)basedir, MYF(0));
basedir= (char *)DEFAULT_MYSQL_HOME;
} }
} }
if (!datadir) if (!datadir)
{ {
datadir= datadir_buf; if (!find_file("mysql", basedir, MYF(MY_ISDIR|MY_PARENT),
if (test_file_exists(bindir, "data/mysql")) path, sizeof(path),
{ "data", "var", NullS))
*strxnmov(datadir_buf, sizeof(datadir_buf)-1, bindir, "/data", NullS)= 0; datadir= my_strdup(path, MYF(0));
}
else if (test_file_exists(bindir, "var/mysql"))
{
*strxnmov(datadir_buf, sizeof(datadir_buf)-1, bindir, "/var", NullS)= 0;
}
else else
datadir= (char*) DATADIR; datadir= (char *)DATADIR;
} }
if (find_file("user.frm", datadir, MYF(0), path, sizeof(path),
strmake(bindir_end, "/bin", sizeof(bindir) - (int) (bindir_end - bindir)-1); "mysql", NullS))
if (!test_file_exists_res
(bindir, mysqlcheck_name, mysqlcheck_line, &mysqlcheck_end))
{ {
printf("Can't find program '%s'\n", mysqlcheck_line); ret= 1;
puts("Please restart with --basedir=mysql-install-directory"); puts("Can't find data directory. Please restart with"
exit(1); " --datadir=path-to-writable-data-dir");
goto error;
} }
if (!test_file_exists(datadir, "mysql/user.frm")) /*
Create the modified defaults file to be used by mysqlcheck
and mysql tools
*/
fn_format(path, UPGRADE_DEFAULTS_NAME, datadir, "", MYF(0));
upgrade_defaults_path= my_strdup(path, MYF(0));
if (extra_defaults)
{ {
puts ret= create_defaults_file(upgrade_defaults_path, forced_extra_defaults);
("Can't find data directory. Please restart with --datadir=path-to-data-dir"); if (ret)
exit(1); goto error;
}
defaults_to_use= upgrade_defaults_path;
/* create the modified defaults file to be used by mysqlcheck */ upgrade_defaults_created= 1;
/* and mysql tools */ }
*strxnmov(upgrade_defaults_path, sizeof(upgrade_defaults_path)-1, else
datadir, "/upgrade_defaults", NullS)= 0; defaults_to_use= forced_extra_defaults;
unpack_filename(upgrade_defaults_path, upgrade_defaults_path);
if ((error=
create_defaults_file(upgrade_defaults_path, forced_extra_defaults)))
goto err_exit;
defaults_to_use= upgrade_defaults_created ?
upgrade_defaults_path : forced_extra_defaults;
if (test_file_exists_res(datadir, "mysql_upgrade_info", check_file_name, if (!find_file(MYSQL_UPGRADE_INFO_NAME, datadir, MY_SEARCH_SELF,
&buf_end) && !opt_force) path, sizeof(path), NULL, NullS)
&& !opt_force)
{ {
char chf_buffer[50]; char buf[sizeof(MYSQL_SERVER_VERSION)];
int b_read; int fd, cnt;
check_file= my_open(check_file_name, O_RDONLY, MYF(0));
b_read= my_read(check_file, chf_buffer, sizeof(chf_buffer)-1, MYF(0)); fd= my_open(path, O_RDONLY, MYF(0));
chf_buffer[b_read]= 0; cnt= my_read(fd, buf, sizeof(buf) - 1, MYF(0));
my_close(check_file, MYF(0)); my_close(fd, MYF(0));
if (!strcmp(chf_buffer, MYSQL_SERVER_VERSION)) buf[cnt]= 0;
if (!strcmp(buf, MYSQL_SERVER_VERSION))
{ {
if (opt_verbose) if (opt_verbose)
puts("mysql_upgrade already done for this version"); puts("mysql_upgrade has already been done for this version");
goto fix_priv_tables; goto fix_priv_tables;
} }
} }
if (find_file(mysqlcheck_name, basedir, MYF(0), path, sizeof(path),
"bin", NullS))
{
ret= 1;
printf("Can't find program '%s'\n", mysqlcheck_name);
puts("Please restart with --basedir=mysql-install-directory");
goto error;
}
else
dynstr_set(&cmdline, path);
if (defaults_to_use) if (defaults_to_use)
{ {
mysqlcheck_end= strxnmov(mysqlcheck_end, dynstr_append(&cmdline, " --defaults-extra-file=");
sizeof(mysqlcheck_line) - (int) (mysqlcheck_end - dynstr_append(&cmdline, defaults_to_use);
mysqlcheck_line),
" --defaults-extra-file=", defaults_to_use,NullS);
} }
mysqlcheck_end= strxnmov(mysqlcheck_end, dynstr_append(&cmdline, " --check-upgrade --all-databases"
sizeof(mysqlcheck_line) - " --auto-repair --user=");
(int) (mysqlcheck_end - mysqlcheck_line - 1), dynstr_append(&cmdline, user);
" --check-upgrade --all-databases --auto-repair --user=",
user, port_socket, NullS);
*mysqlcheck_end= 0;
if (opt_verbose) if (opt_verbose)
printf("Running %s\n", mysqlcheck_line); printf("Running %s\n", cmdline.str);
if ((error= system(mysqlcheck_line)))
ret= system(cmdline.str);
if (ret)
{ {
printf("Error executing '%s'\n", mysqlcheck_line); printf("Error executing '%s'\n", cmdline.str);
goto err_exit; goto error;
} }
if ((error= create_check_file(check_file_name))) fn_format(path, MYSQL_UPGRADE_INFO_NAME, datadir, "", MYF(0));
goto err_exit; ret= create_check_file(path);
if (ret)
goto error;
fix_priv_tables: fix_priv_tables:
if (!test_file_exists_res(bindir, mysql_name, if (find_file(mysql_name, basedir, MYF(0), path, sizeof(path),
fix_priv_tables_cmd, &fix_cmd_end)) "bin", NullS))
{ {
puts("Could not find MySQL command-line client (mysql)."); ret= 1;
puts puts("Could not find MySQL command-line client (mysql).\n"
("Please use --basedir to specify the directory where MySQL is installed."); "Please use --basedir to specify the directory"
error= 1; " where MySQL is installed.");
goto err_exit; goto error;
} }
else
if (!test_file_exists_res(basedir, dynstr_set(&cmdline, path);
"support_files/mysql_fix_privilege_tables.sql",
script_line, &buf_end) if (find_file(MYSQL_FIX_PRIV_TABLES_NAME, basedir, MYF(0),
&& !test_file_exists_res(basedir, "share/mysql_fix_privilege_tables.sql", path, sizeof(path),
script_line, &buf_end) "support_files", "share/mysql", "scripts",
&& !test_file_exists_res(basedir, NullS)
"share/mysql/mysql_fix_privilege_tables.sql", && find_file(MYSQL_FIX_PRIV_TABLES_NAME, "/usr/local/mysql", MYF(0),
script_line, &buf_end) path, sizeof(path),
&& !test_file_exists_res(basedir, "share/mysql", NullS))
"scripts/mysql_fix_privilege_tables.sql",
script_line, &buf_end)
&& !test_file_exists_res("/usr/local/mysql/share/mysql",
"mysql_fix_privilege_tables.sql", script_line,
&buf_end))
{ {
puts("Could not find file mysql_fix_privilege_tables.sql"); ret= 1;
puts puts("Could not find file " MYSQL_FIX_PRIV_TABLES_NAME "\n"
("Please use --basedir to specify the directory where MySQL is installed"); "Please use --basedir to specify the directory"
error= 1; " where MySQL is installed");
goto err_exit; goto error;
} }
else
script_line= my_strdup(path, MYF(0));
if (defaults_to_use) if (defaults_to_use)
{ {
fix_cmd_end= strxnmov(fix_cmd_end, dynstr_append(&cmdline, " --defaults-extra-file=");
sizeof(fix_priv_tables_cmd) - dynstr_append(&cmdline, defaults_to_use);
(int) (fix_cmd_end - fix_priv_tables_cmd - 1),
" --defaults-extra-file=", defaults_to_use, NullS);
} }
fix_cmd_end= strxnmov(fix_cmd_end, dynstr_append(&cmdline, " --force --no-auto-rehash --batch --user=");
sizeof(fix_priv_tables_cmd) - (int) (fix_cmd_end - dynstr_append(&cmdline, user);
fix_priv_tables_cmd), dynstr_append(&cmdline, " mysql < ");
" --user=", user, port_socket, " mysql < ", script_line, NullS); dynstr_append(&cmdline, script_line);
*fix_cmd_end= 0;
if ((error= system(fix_priv_tables_cmd))) if (opt_verbose)
{ printf("Running %s\n", cmdline.str);
/* Problem is that the 'Duplicate column' error */
/* which is not a bug for the script makes 'mysql' return */ ret= system(cmdline.str);
/* an error */ if (ret)
/* printf("Error executing '%s'\n", fix_priv_tables_cmd); */ printf("Error executing '%s'\n", cmdline.str);
}
error:
dynstr_free(&cmdline);
err_exit:
if (upgrade_defaults_created) if (upgrade_defaults_created)
my_delete(upgrade_defaults_path, MYF(0)); my_delete(upgrade_defaults_path, MYF(0));
my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0); my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
return error; return ret;
} /* main */ }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment