diff options
author | Oleksandr Byelkin <sanja@askmonty.org> | 2015-04-12 15:56:21 +1000 |
---|---|---|
committer | Daniel Black <grooverdan@users.sourceforge.net> | 2015-04-12 15:56:21 +1000 |
commit | 70960e7ab7e1d8d1872cd6882ce4a5d870283288 (patch) | |
tree | 7a0a71566a4fbbd168f4ac939b69cbdc70921cdd /client | |
parent | cc84ac3be41d9d6ac480d55449d5bf4e324cca10 (diff) | |
download | mariadb-git-70960e7ab7e1d8d1872cd6882ce4a5d870283288.tar.gz |
MDEV-6916: Upgrade from MySQL to MariaDB breaks already created views
mysql_upgrade upgrades views`
from r4408:
missing files from mysql-test/std_data/mysql_upgrade/*
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql_upgrade.c | 69 | ||||
-rw-r--r-- | client/mysqlcheck.c | 45 |
2 files changed, 105 insertions, 9 deletions
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 5fb3b1317d9..acb480da570 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -40,7 +40,8 @@ static char mysql_path[FN_REFLEN]; static char mysqlcheck_path[FN_REFLEN]; static my_bool opt_force, opt_verbose, debug_info_flag, debug_check_flag, - opt_systables_only, opt_version_check; + opt_systables_only, opt_version_check, + opt_mysql_upgrade= 0, opt_skip_mysql_upgrade= 0; static my_bool opt_not_used, opt_silent; static uint my_end_arg= 0; static char *opt_user= (char*)"root"; @@ -150,6 +151,14 @@ static struct my_option my_long_options[]= &opt_not_used, &opt_not_used, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"mysql-upgrade", 'y', + "Skip automatic detection MySQL and assume that we upgrade it", + &opt_mysql_upgrade, &opt_mysql_upgrade, 0, GET_BOOL, NO_ARG, + 0, 0, 0, 0, 0, 0}, + {"skip-mysql-upgrade", 'Y', + "Skip view algorithm upgrade from MySQL", + &opt_skip_mysql_upgrade, &opt_skip_mysql_upgrade, 0, GET_BOOL, NO_ARG, + 0, 0, 0, 0, 0, 0}, {"version-check", 'k', "Run this program only if its \'server version\' " "matches the version of the server to which it's connecting, (enabled by " "default); use --skip-version-check to avoid this check. Note: the \'server " @@ -344,6 +353,14 @@ get_one_option(int optid, const struct my_option *opt, case OPT_DEFAULT_AUTH: /* --default-auth */ add_one_option(&conn_args, opt, argument); break; + case 'y': + opt_mysql_upgrade= 1; + add_option= FALSE; + break; + case 'Y': + opt_skip_mysql_upgrade= 1; + add_option= FALSE; + break; } if (add_option) @@ -754,6 +771,23 @@ static int run_mysqlcheck_upgrade(void) NULL); } +static int run_mysqlcheck_views(void) +{ + if (!opt_mysql_upgrade) + return 0; + verbose("Phase 0: Fixing views"); + print_conn_args("mysqlcheck"); + return run_tool(mysqlcheck_path, + NULL, /* Send output from mysqlcheck directly to screen */ + "--no-defaults", + ds_args.str, + "--all-databases", + "--mysql-upgrade", + opt_verbose ? "--verbose": "", + opt_silent ? "--silent": "", + "2>&1", + NULL); +} static int run_mysqlcheck_fixnames(void) { @@ -928,6 +962,28 @@ static int check_version_match(void) return 0; } +#define EVENTS_STRUCT_LEN 7000 + +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 + verbose("MySQL upgrade detected"); + + dynstr_free(&ds_events_struct); + return(ret); +} + int main(int argc, char **argv) { @@ -997,11 +1053,20 @@ int main(int argc, char **argv) if (opt_version_check && check_version_match()) die("Upgrade failed"); + if (!opt_systables_only && !opt_skip_mysql_upgrade) + { + if (!opt_mysql_upgrade) + opt_mysql_upgrade= is_mysql(); + } + else + opt_mysql_upgrade= 0; + /* Run "mysqlcheck" and "mysql_fix_privilege_tables.sql" */ if ((!opt_systables_only && - (run_mysqlcheck_fixnames() || run_mysqlcheck_upgrade())) || + (run_mysqlcheck_views() || + run_mysqlcheck_fixnames() || run_mysqlcheck_upgrade())) || run_sql_fix_privilege_tables()) { /* diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index a4549432c2c..7446d75d0a3 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -42,7 +42,8 @@ static my_bool opt_alldbs = 0, opt_check_only_changed = 0, opt_extended = 0, opt_medium_check = 0, opt_quick = 0, opt_all_in_1 = 0, opt_silent = 0, opt_auto_repair = 0, ignore_errors = 0, tty_password= 0, opt_frm= 0, debug_info_flag= 0, debug_check_flag= 0, - opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0; + opt_fix_table_names= 0, opt_fix_db_names= 0, opt_upgrade= 0, + opt_mysql_upgrade= 0; static my_bool opt_write_binlog= 1, opt_flush_tables= 0; static uint verbose = 0, opt_mysql_port=0; static int my_end_arg; @@ -196,6 +197,9 @@ static struct my_option my_long_options[] = NO_ARG, 0, 0, 0, 0, 0, 0}, {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, + {"mysql-upgrade", 'y', + "Fix view algorithm view field if it is not new MariaDB view.", + 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} }; @@ -332,7 +336,13 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'v': verbose++; break; - case 'V': print_version(); exit(0); + case 'V': + print_version(); exit(0); + break; + case 'y': + what_to_do= DO_REPAIR; + opt_mysql_upgrade= 1; + break; case OPT_MYSQL_PROTOCOL: opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib, opt->name); @@ -587,7 +597,15 @@ static int process_all_tables_in_db(char *database) for (end = tables + 1; (row = mysql_fetch_row(res)) ;) { if ((num_columns == 2) && (strcmp(row[1], "VIEW") == 0)) - continue; + { + if (!opt_mysql_upgrade) + continue; + } + else + { + if (opt_mysql_upgrade) + continue; + } end= fix_table_name(end, row[0]); *end++= ','; @@ -603,7 +621,15 @@ static int process_all_tables_in_db(char *database) { /* Skip views if we don't perform renaming. */ if ((what_to_do != DO_UPGRADE) && (num_columns == 2) && (strcmp(row[1], "VIEW") == 0)) - continue; + { + if (!opt_mysql_upgrade) + continue; + } + else + { + if (opt_mysql_upgrade) + continue; + } if (system_database && (!strcmp(row[0], "general_log") || !strcmp(row[0], "slow_log"))) @@ -748,10 +774,12 @@ static int handle_request_for_tables(char *tables, uint length) if (opt_upgrade) end = strmov(end, " FOR UPGRADE"); break; case DO_REPAIR: - op= (opt_write_binlog) ? "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG"; + op= ((opt_write_binlog || opt_mysql_upgrade) ? + "REPAIR" : "REPAIR NO_WRITE_TO_BINLOG"); if (opt_quick) end = strmov(end, " QUICK"); if (opt_extended) end = strmov(end, " EXTENDED"); if (opt_frm) end = strmov(end, " USE_FRM"); + if (opt_mysql_upgrade) end = strmov(end, " FROM MYSQL"); break; case DO_ANALYZE: op= (opt_write_binlog) ? "ANALYZE" : "ANALYZE NO_WRITE_TO_BINLOG"; @@ -768,14 +796,17 @@ static int handle_request_for_tables(char *tables, uint length) if (opt_all_in_1) { /* No backticks here as we added them before */ - query_length= sprintf(query, "%s TABLE %s %s", op, tables, options); + query_length= sprintf(query, "%s %s %s %s", op, + (opt_mysql_upgrade ? "VIEW" : "TABLE"), + tables, options); table_name= tables; } else { char *ptr, *org; - org= ptr= strmov(strmov(query, op), " TABLE "); + org= ptr= strmov(strmov(query, op), + (opt_mysql_upgrade ? " VIEW " : " TABLE ")); ptr= fix_table_name(ptr, tables); strmake(table_name_buff, org, min((int) sizeof(table_name_buff)-1, (int) (ptr - org))); |