mysql_upgrade.c 17.9 KB
Newer Older
1 2 3 4
/* Copyright (C) 2000 MySQL AB

   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
unknown's avatar
unknown committed
5
   the Free Software Foundation; version 2 of the License.
6 7 8 9 10 11 12 13 14 15 16 17

   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
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

#include "client_priv.h"
#include <my_dir.h>
18 19 20 21 22 23 24 25 26 27
#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)
28

29 30 31
#ifdef __WIN__
const char *mysqlcheck_name= "mysqlcheck.exe";
const char *mysql_name= "mysql.exe";
32
const char *mysqld_name= "mysqld.exe";
33
#define EXTRA_CLIENT_PATHS "client/release", "client/debug"
34 35 36
#else
const char *mysqlcheck_name= "mysqlcheck";
const char *mysql_name= "mysql";
37
const char *mysqld_name= "mysqld";
38
#define EXTRA_CLIENT_PATHS "client"
39 40
#endif /*__WIN__*/

41 42 43
extern TYPELIB sql_protocol_typelib;

static my_bool opt_force= 0, opt_verbose= 0, opt_compress= 0;
44
static char *user= (char*) "root", *basedir= 0, *datadir= 0, *opt_password= 0;
45 46 47 48 49 50 51 52 53 54 55
static char *current_host= 0;
static char *opt_default_charset= 0, *opt_charsets_dir= 0;
#ifdef HAVE_SMEM
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;
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74

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},
  {"basedir", 'b', "Specifies the directory where MySQL is installed",
   (gptr*) &basedir,
   (gptr*) &basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
  {"datadir", 'd', "Specifies the data directory", (gptr*) &datadir,
   (gptr*) &datadir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
#ifdef DBUG_OFF
  {"debug", '#', "This is a non-debug version. Catch this and exit",
   0, 0, 0, GET_DISABLED, OPT_ARG, 0, 0, 0, 0, 0, 0},
#else
  {"debug", '#', "Output debug log", (gptr *) & default_dbug_option,
   (gptr *) & default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#endif
  {"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},
75 76 77 78 79
  {"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.",
80 81
   (gptr*) &opt_force, (gptr*) &opt_force, 0, GET_BOOL, NO_ARG, 0, 0,
   0, 0, 0, 0},
82 83 84 85 86 87 88 89
  {"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},
90
  {"password", 'p',
91 92 93 94 95 96
   "Password to use when connecting to server. If password is not given"
   " it's solicited on the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
#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
97
  {"port", 'P', "Port number to use for connection.", (gptr*) &opt_mysql_port,
98
   (gptr*) &opt_mysql_port, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
99 100 101
  {"protocol", OPT_MYSQL_PROTOCOL,
   "The protocol of connection (tcp,socket,pipe,memory).",
   0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
102 103 104 105 106 107
#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
108
  {"socket", 'S', "Socket file to use for connection.",
109 110
   (gptr*) &opt_mysql_unix_port, (gptr*) &opt_mysql_unix_port, 0, 
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
111 112
  {"user", 'u', "User for login if not current user.", (gptr*) &user,
   (gptr*) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
113 114 115 116
#include <sslopt-longopts.h>
  {"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},
117 118
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
};
119

120 121
static const char *load_default_groups[]=
{
122
  "mysql_upgrade", 0
123 124 125 126
};

#include <help_end.h>

127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
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 */
unknown's avatar
unknown committed
146
  case 'p':             /* --password may change yet */
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
    /* 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);
unknown's avatar
unknown committed
178
      if (opt->arg_type != NO_ARG && opt->value)
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
        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);
    }
  }
}


203 204 205 206 207 208 209
static my_bool
get_one_option(int optid, const struct my_option *opt __attribute__ ((unused)),
               char *argument)
{
  switch (optid) {
  case '?':
    puts
210
      ("MySQL utility to upgrade database to the current server version");
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
    puts("");
    my_print_help(my_long_options);
    exit(0);
  case '#':
    DBUG_PUSH(argument ? argument : default_dbug_option);
    break;
  case 'p':
    tty_password= 1;
    if (argument)
    {
      char *start= argument;
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
      opt_password= my_strdup(argument, MYF(MY_FAE));
      while (*argument)
        *argument++= 'x';                       /* Destroy argument */
      if (*start)
        start[1]= 0;                            /* Cut length of argument */
      tty_password= 0;
    }
    break;
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
#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>
250
  default:;
251 252
  }
  set_extra_default(opt->id, opt);
253 254 255 256 257 258
  return 0;
}


static int create_check_file(const char *path)
{
259 260 261 262 263 264 265 266 267 268
  int ret;
  File fd;
  
  fd= my_open(path, O_CREAT | O_WRONLY, MYF(MY_FAE | MY_WME));
  if (fd < 0) {
    ret= 1;
    goto error;
  }
  ret= my_write(fd, MYSQL_SERVER_VERSION, 
                  sizeof(MYSQL_SERVER_VERSION) - 1,
unknown's avatar
unknown committed
269
                  MYF(MY_WME | MY_FNABP));
270 271 272
  ret|= my_close(fd, MYF(MY_FAE | MY_WME));
error:
  return ret;
273 274 275
}


276
static int create_defaults_file(const char *path, const char *forced_path)
277
{
278 279 280 281 282 283 284 285 286
  int ret;
  uint cnt;
  File forced_file, defaults_file;
  
  DYNAMIC_STRING buf;
  extra_default_t *d;

  my_delete(path, MYF(0));
  
287
  defaults_file= my_open(path, O_BINARY | O_CREAT | O_WRONLY | O_EXCL,
288 289
                         MYF(MY_FAE | MY_WME));
  if (defaults_file < 0)
290
  {
291 292 293 294 295 296 297 298
    ret= 1;
    goto out;
  }

  if (init_dynamic_string(&buf, NULL, my_getpagesize(), FN_REFLEN))
  {
    ret= 1;
    goto error;
299 300
  }

301
  if (forced_path)
302
  {
303 304 305 306 307 308
    forced_file= my_open(forced_path, O_RDONLY, MYF(MY_FAE | MY_WME));
    if (forced_file < 0)
    {
      ret= 1;
      goto error;
    }
309 310
    do
    {
311 312 313
      cnt= my_read(forced_file, buf.str, buf.max_length, MYF(MY_WME));
      if ((cnt == MY_FILE_ERROR)
           || my_write(defaults_file, buf.str, cnt, MYF(MY_FNABP | MY_WME)))
314
      {
315 316 317
        ret= 1;
        my_close(forced_file, MYF(0));
        goto error;
318
      }
319 320
    } while (cnt == buf.max_length);
    my_close(forced_file, MYF(0));
321
  }
322 323
  
  dynstr_set(&buf, "\n[client]");
unknown's avatar
unknown committed
324 325
  if (opt_password) 
  {
unknown's avatar
unknown committed
326 327
    if (dynstr_append(&buf, "\npassword=")
       || dynstr_append(&buf, opt_password))
unknown's avatar
unknown committed
328 329 330 331 332
    {
      ret = 1;
      goto error;
    }
  }
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
  while (extra_defaults) 
  {
    int len;
        
    d= extra_defaults->data;
    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));
}


unknown's avatar
unknown committed
387 388
static int find_file(const char *name, const char *root,
                     uint flags, char *result, size_t len, ...)
389
{
unknown's avatar
unknown committed
390
  int ret= 1;
391 392 393
  va_list va;
  const char *subdir;
  char *cp;
unknown's avatar
unknown committed
394 395 396 397 398
  FILEINFO key;

  /* Init key with name of the file to look for */
  key.name= (char*)name;

399 400 401 402
  DBUG_ASSERT(root != NULL);

  cp= strmake(result, root, len);
  if (cp[-1] != FN_LIBCHAR) 
unknown's avatar
unknown committed
403
    *cp++= FN_LIBCHAR; 
404 405 406
  
  va_start(va, len);
  subdir= (!(flags & MY_SEARCH_SELF)) ? va_arg(va, char *) : "";
unknown's avatar
unknown committed
407
  while (subdir)
408 409 410 411 412
  {
    MY_DIR *dir;
    FILEINFO *match;
    char *cp1;
    
unknown's avatar
unknown committed
413
    cp1= strnmov(cp, subdir, len - (cp - result) - 1);
414 415 416 417 418 419 420 421
    
    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)
      {
unknown's avatar
unknown committed
422 423 424 425
        ret= (flags & MY_ISDIR) ? !MY_S_ISDIR(match->mystat->st_mode) : 0;
        if (!ret)
        { 
          if (cp1[-1] != FN_LIBCHAR)
426
            *cp1++= FN_LIBCHAR;
unknown's avatar
unknown committed
427 428 429 430 431 432 433 434
          
          if (!(flags & MY_PARENT)) 
            strnmov(cp1, name, len - (cp1 - result));
          else
            *cp1= '\0';
          
          my_dirend(dir);
          break;
435 436 437 438 439 440 441 442
        }
      }
      my_dirend(dir);
    }
    subdir= va_arg(va, char *);
  }
  va_end(va);
  return ret;
443 444 445 446 447
}


int main(int argc, char **argv)
{
448 449
  int ret;
  
450 451 452
  char *forced_defaults_file;
  char *forced_extra_defaults;
  char *defaults_group_suffix;
453 454 455 456 457 458 459
  const char *script_line;
  char *upgrade_defaults_path; 
  char *defaults_to_use= NULL;
  int upgrade_defaults_created= 0;
  
  char path[FN_REFLEN];
  DYNAMIC_STRING cmdline;
460 461 462 463 464 465

  MY_INIT(argv[0]);
#ifdef __NETWARE__
  setscreenmode(SCR_AUTOCLOSE_ON_EXIT);
#endif

466 467 468 469 470
  /* Check if we are forced to use specific defaults */
  get_defaults_options(argc, argv,
                       &forced_defaults_file, &forced_extra_defaults,
                       &defaults_group_suffix);
  
471 472
  load_defaults("my", load_default_groups, &argc, &argv);

473 474 475 476 477
  if (handle_options(&argc, &argv, my_long_options, get_one_option)) 
  {
    ret= 1;
    goto error;
  }
478 479 480
  if (tty_password)
    opt_password= get_tty_password(NullS);

481
  if (init_dynamic_string(&cmdline, NULL, 2 * FN_REFLEN + 128, FN_REFLEN))
482
  {
483 484
    ret= 1;
    goto error;
485
  }
486
  if (!basedir)
487
  {
488 489 490 491 492 493
    my_getwd(path, sizeof(path), MYF(0));
    basedir= my_strdup(path, MYF(0));
    if (find_file("errmsg.sys", basedir, MYF(0), path, sizeof(path),
                              "share/mysql/english", NullS)
       || find_file(mysqld_name, basedir, MYF(0), path, sizeof(path),
                              "bin", "libexec", NullS))
494
    {
unknown's avatar
unknown committed
495
      my_free((gptr)basedir, MYF(0));
496
      basedir= (char *)DEFAULT_MYSQL_HOME;
497 498 499 500 501
    }
  }

  if (!datadir)
  {
502 503 504 505
    if (!find_file("mysql", basedir, MYF(MY_ISDIR|MY_PARENT), 
                            path, sizeof(path),
                            "data", "var", NullS))
      datadir= my_strdup(path, MYF(0));
506
    else
507
      datadir= (char *)DATADIR;
508
  }
509 510
  if (find_file("user.frm", datadir, MYF(0), path, sizeof(path), 
                          "mysql", NullS))
511
  {
512
    ret= 1;
513 514 515
    fprintf(stderr,
            "Can't find data directory. Please restart with"
            " --datadir=path-to-writable-data-dir");
516
    goto error;
517 518
  }

519 520 521 522 523 524 525 526
  /* 
     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) 
527
  {
528 529 530 531 532 533 534 535 536
    ret= create_defaults_file(upgrade_defaults_path, forced_extra_defaults);
    if (ret)
      goto error;
    
    defaults_to_use= upgrade_defaults_path;
    upgrade_defaults_created= 1;
  } 
  else
    defaults_to_use= forced_extra_defaults;
537

538 539 540
  if (!find_file(MYSQL_UPGRADE_INFO_NAME, datadir, MY_SEARCH_SELF, 
                          path, sizeof(path), NULL, NullS)
     && !opt_force)
541
  {
542 543 544 545 546 547 548 549
    char buf[sizeof(MYSQL_SERVER_VERSION)];
    int fd, cnt;
   
    fd= my_open(path, O_RDONLY, MYF(0));
    cnt= my_read(fd, buf, sizeof(buf) - 1, MYF(0));
    my_close(fd, MYF(0));
    buf[cnt]= 0;
    if (!strcmp(buf, MYSQL_SERVER_VERSION))
550 551
    {
      if (opt_verbose)
552
        puts("mysql_upgrade has already been done for this version");
553 554 555
      goto fix_priv_tables;
    }
  }
556 557
  
  if (find_file(mysqlcheck_name, basedir, MYF(0), path, sizeof(path),
558
                "bin", EXTRA_CLIENT_PATHS, NullS))
559 560
  {
     ret= 1;
561 562 563 564
     fprintf(stderr,
             "Can't find program '%s'\n"
             "Please restart with --basedir=mysql-install-directory",
             mysqlcheck_name);
565 566 567 568
     goto error;
  }
  else
    dynstr_set(&cmdline, path);
569 570 571

  if (defaults_to_use)
  {
572 573
    dynstr_append(&cmdline, " --defaults-extra-file=");
    dynstr_append(&cmdline, defaults_to_use);
574
  }
575 576 577 578
  
  dynstr_append(&cmdline, " --check-upgrade --all-databases"
                 " --auto-repair --user=");
  dynstr_append(&cmdline, user);
579 580

  if (opt_verbose)
581 582 583 584
    printf("Running %s\n", cmdline.str);

  ret= system(cmdline.str);
  if (ret)
585
  {
586
    fprintf(stderr, "Error executing '%s'\n", cmdline.str);
587
    goto error;
588 589
  }

590 591 592 593
  fn_format(path, MYSQL_UPGRADE_INFO_NAME, datadir, "", MYF(0));
  ret= create_check_file(path);
  if (ret)
    goto error;
594 595

fix_priv_tables:
596
  if (find_file(mysql_name, basedir, MYF(0), path, sizeof(path), 
597
                "bin", EXTRA_CLIENT_PATHS, NullS))
598
  {
599
    ret= 1;
600 601 602 603
    fprintf(stderr,
           "Could not find MySQL command-line client (mysql).\n"
           "Please use --basedir to specify the directory"
           " where MySQL is installed.");
604
    goto error;
605
  }
606 607 608 609 610
  else
    dynstr_set(&cmdline, path);

  if (find_file(MYSQL_FIX_PRIV_TABLES_NAME, basedir, MYF(0), 
                          path, sizeof(path), 
611
                          "support_files", "share", "share/mysql", "scripts",
612 613 614 615
                          NullS)
     && find_file(MYSQL_FIX_PRIV_TABLES_NAME, "/usr/local/mysql", MYF(0),
                          path, sizeof(path),
                          "share/mysql", NullS))
616
  {
617
    ret= 1;
618 619 620 621
    fprintf(stderr,
           "Could not find file " MYSQL_FIX_PRIV_TABLES_NAME "\n"
           "Please use --basedir to specify the directory"
           " where MySQL is installed");
622
    goto error;
623
  }
624 625
  else
    script_line= my_strdup(path, MYF(0));
626 627 628

  if (defaults_to_use)
  {
629 630
    dynstr_append(&cmdline, " --defaults-extra-file=");
    dynstr_append(&cmdline, defaults_to_use);
631
  }
632 633 634 635
  dynstr_append(&cmdline, " --force --no-auto-rehash --batch --user=");
  dynstr_append(&cmdline, user);
  dynstr_append(&cmdline, " mysql < ");
  dynstr_append(&cmdline, script_line);
636

637 638 639 640 641
  if (opt_verbose)
    printf("Running %s\n", cmdline.str);

  ret= system(cmdline.str);
  if (ret)
642
    fprintf(stderr, "Error executing '%s'\n", cmdline.str);
643 644 645

error:
  dynstr_free(&cmdline);
646 647 648

  if (upgrade_defaults_created)
    my_delete(upgrade_defaults_path, MYF(0));
649
  
650
  my_end(info_flag ? MY_CHECK_ERROR | MY_GIVE_INFO : 0);
651 652 653
  return ret;
}