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/*
This commit is contained in:
parent
cc84ac3be4
commit
70960e7ab7
@ -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())
|
||||
{
|
||||
/*
|
||||
|
@ -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)));
|
||||
|
74
mysql-test/r/mysql_upgrade_view.result
Normal file
74
mysql-test/r/mysql_upgrade_view.result
Normal file
@ -0,0 +1,74 @@
|
||||
drop table if exists t1,v1,v2,v3,v4;
|
||||
drop view if exists t1,v1,v2,v3,v4;
|
||||
flush tables;
|
||||
create table t1(a int);
|
||||
create algorithm=temptable view v4 as select a from t1;
|
||||
show create view v1;
|
||||
View Create View character_set_client collation_connection
|
||||
v1 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
|
||||
show create view v2;
|
||||
View Create View character_set_client collation_connection
|
||||
v2 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
|
||||
show create view v3;
|
||||
View Create View character_set_client collation_connection
|
||||
v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
|
||||
show create view v4;
|
||||
View Create View character_set_client collation_connection
|
||||
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci
|
||||
MySQL upgrade detected
|
||||
Phase 0: Fixing views
|
||||
test.v1 view is repaired
|
||||
test.v2 view is repaired
|
||||
test.v3 view is repaired
|
||||
test.v4 OK
|
||||
Phase 1/3: Fixing table and database names
|
||||
Phase 2/3: Checking and upgrading tables
|
||||
Processing databases
|
||||
information_schema
|
||||
mtr
|
||||
mtr.global_suppressions OK
|
||||
mtr.test_suppressions OK
|
||||
mysql
|
||||
mysql.columns_priv OK
|
||||
mysql.db OK
|
||||
mysql.ev_bk OK
|
||||
mysql.event OK
|
||||
mysql.func OK
|
||||
mysql.help_category OK
|
||||
mysql.help_keyword OK
|
||||
mysql.help_relation OK
|
||||
mysql.help_topic OK
|
||||
mysql.host OK
|
||||
mysql.ndb_binlog_index OK
|
||||
mysql.plugin OK
|
||||
mysql.proc OK
|
||||
mysql.procs_priv OK
|
||||
mysql.proxies_priv OK
|
||||
mysql.servers OK
|
||||
mysql.tables_priv OK
|
||||
mysql.time_zone OK
|
||||
mysql.time_zone_leap_second OK
|
||||
mysql.time_zone_name OK
|
||||
mysql.time_zone_transition OK
|
||||
mysql.time_zone_transition_type OK
|
||||
mysql.user OK
|
||||
performance_schema
|
||||
test
|
||||
test.t1 OK
|
||||
Phase 3/3: Running 'mysql_fix_privilege_tables'...
|
||||
OK
|
||||
show create view v1;
|
||||
View Create View character_set_client collation_connection
|
||||
v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
|
||||
show create view v2;
|
||||
View Create View character_set_client collation_connection
|
||||
v2 CREATE ALGORITHM=MERGE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
|
||||
show create view v3;
|
||||
View Create View character_set_client collation_connection
|
||||
v3 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v3` AS select `t1`.`a` AS `a` from `t1` utf8 utf8_general_ci
|
||||
show create view v4;
|
||||
View Create View character_set_client collation_connection
|
||||
v4 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v4` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci
|
||||
flush tables;
|
||||
drop view v1,v2,v3,v4;
|
||||
drop table t1;
|
53
mysql-test/t/mysql_upgrade_view.test
Normal file
53
mysql-test/t/mysql_upgrade_view.test
Normal file
@ -0,0 +1,53 @@
|
||||
|
||||
--disable_warnings
|
||||
drop table if exists t1,v1,v2,v3,v4;
|
||||
drop view if exists t1,v1,v2,v3,v4;
|
||||
--enable_warnings
|
||||
|
||||
let $MYSQLD_DATADIR= `select @@datadir`;
|
||||
|
||||
--copy_file $MYSQLD_DATADIR/mysql/event.MYI $MYSQLD_DATADIR/mysql/ev_bk.MYI
|
||||
--copy_file $MYSQLD_DATADIR/mysql/event.MYD $MYSQLD_DATADIR/mysql/ev_bk.MYD
|
||||
--copy_file $MYSQLD_DATADIR/mysql/event.frm $MYSQLD_DATADIR/mysql/ev_bk.frm
|
||||
--remove_file $MYSQLD_DATADIR/mysql/event.MYI
|
||||
--remove_file $MYSQLD_DATADIR/mysql/event.MYD
|
||||
--remove_file $MYSQLD_DATADIR/mysql/event.frm
|
||||
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.MYI $MYSQLD_DATADIR/mysql/event.MYI
|
||||
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.MYD $MYSQLD_DATADIR/mysql/event.MYD
|
||||
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/event.frm $MYSQLD_DATADIR/mysql/event.frm
|
||||
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v1.frm $MYSQLD_DATADIR/test/v1.frm
|
||||
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v2.frm $MYSQLD_DATADIR/test/v2.frm
|
||||
--copy_file $MYSQL_TEST_DIR/std_data/mysql_upgrade/v3.frm $MYSQLD_DATADIR/test/v3.frm
|
||||
|
||||
flush tables;
|
||||
|
||||
create table t1(a int);
|
||||
create algorithm=temptable view v4 as select a from t1;
|
||||
show create view v1;
|
||||
show create view v2;
|
||||
show create view v3;
|
||||
show create view v4;
|
||||
|
||||
--replace_result $MYSQLTEST_VARDIR var
|
||||
--exec $MYSQL_UPGRADE --force 2>&1
|
||||
|
||||
show create view v1;
|
||||
show create view v2;
|
||||
show create view v3;
|
||||
show create view v4;
|
||||
|
||||
--remove_file $MYSQLD_DATADIR/mysql/event.MYI
|
||||
--remove_file $MYSQLD_DATADIR/mysql/event.MYD
|
||||
--remove_file $MYSQLD_DATADIR/mysql/event.frm
|
||||
--copy_file $MYSQLD_DATADIR/mysql/ev_bk.MYI $MYSQLD_DATADIR/mysql/event.MYI
|
||||
--copy_file $MYSQLD_DATADIR/mysql/ev_bk.MYD $MYSQLD_DATADIR/mysql/event.MYD
|
||||
--copy_file $MYSQLD_DATADIR/mysql/ev_bk.frm $MYSQLD_DATADIR/mysql/event.frm
|
||||
--remove_file $MYSQLD_DATADIR/mysql/ev_bk.MYI
|
||||
--remove_file $MYSQLD_DATADIR/mysql/ev_bk.MYD
|
||||
--remove_file $MYSQLD_DATADIR/mysql/ev_bk.frm
|
||||
flush tables;
|
||||
|
||||
drop view v1,v2,v3,v4;
|
||||
drop table t1;
|
||||
|
||||
#select sleep(100);
|
Loading…
x
Reference in New Issue
Block a user