diff options
author | Sergei Golubchik <serg@mariadb.org> | 2022-05-08 15:02:19 +0200 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2022-05-08 23:03:08 +0200 |
commit | a70a1cf3f4ed10c9d9194b2b8df6b6f08551a937 (patch) | |
tree | 517124ec5059f48bff1e02b934355e8162183efc /client/mysqldump.c | |
parent | 40b8f3ec1a76fc23eb6bf9c5a8fef1debcbf5843 (diff) | |
parent | 79660e59ee8fcd23f928c72dc77682b875bd58ce (diff) | |
download | mariadb-git-a70a1cf3f4ed10c9d9194b2b8df6b6f08551a937.tar.gz |
Merge branch '10.3' into 10.4
Diffstat (limited to 'client/mysqldump.c')
-rw-r--r-- | client/mysqldump.c | 106 |
1 files changed, 68 insertions, 38 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c index fc5b3bfabaf..34a207208f8 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2747,6 +2747,9 @@ static uint dump_routines_for_db(char *db) create_caption_xml[i]); continue; } + + switch_sql_mode(sql_file, ";", row[1]); + if (opt_drop) fprintf(sql_file, "/*!50003 DROP %s IF EXISTS %s */;\n", routine_type[i], routine_name); @@ -2786,9 +2789,6 @@ static uint dump_routines_for_db(char *db) "--\n"); } - - switch_sql_mode(sql_file, ";", row[1]); - fprintf(sql_file, "DELIMITER ;;\n" "%s ;;\n" @@ -5220,6 +5220,55 @@ int init_dumping_views(char *qdatabase __attribute__((unused))) /* +mysql specific database initialization. + +SYNOPSIS + init_dumping_mysql_tables + + protections around dumping general/slow query log + qdatabase quoted name of the "mysql" database + +RETURN VALUES + 0 Success. + 1 Failure. +*/ +static int init_dumping_mysql_tables(char *qdatabase) +{ + DBUG_ENTER("init_dumping_mysql_tables"); + + if (opt_drop_database) + fprintf(md_result_file, + "\n/*!50106 SET @save_log_output=@@LOG_OUTPUT*/;\n" + "/*M!100203 EXECUTE IMMEDIATE IF(@@LOG_OUTPUT='TABLE' AND (@@SLOW_QUERY_LOG=1 OR @@GENERAL_LOG=1)," + "\"SET GLOBAL LOG_OUTPUT='NONE'\", \"DO 0\") */;\n"); + + DBUG_RETURN(init_dumping_tables(qdatabase)); +} + + +static void dump_first_mysql_tables(char *database) +{ + char table_type[NAME_LEN]; + char ignore_flag; + DBUG_ENTER("dump_first_mysql_tables"); + + if (!get_table_structure((char *) "general_log", + database, table_type, &ignore_flag) ) + verbose_msg("-- Warning: get_table_structure() failed with some internal " + "error for 'general_log' table\n"); + if (!get_table_structure((char *) "slow_log", + database, table_type, &ignore_flag) ) + verbose_msg("-- Warning: get_table_structure() failed with some internal " + "error for 'slow_log' table\n"); + /* general and slow query logs exist now */ + if (opt_drop_database) + fprintf(md_result_file, + "\n/*!50106 SET GLOBAL LOG_OUTPUT=@save_log_output*/;\n\n"); + DBUG_VOID_RETURN; +} + + +/* Table Specific database initialization. SYNOPSIS @@ -5325,7 +5374,6 @@ static int dump_all_tables_in_db(char *database) char table_buff[NAME_LEN*2+3]; char hash_key[2*NAME_LEN+2]; /* "db.tablename" */ char *afterdot; - my_bool general_log_table_exists= 0, slow_log_table_exists=0; my_bool transaction_registry_table_exists= 0; int using_mysql_db= !my_strcasecmp(charset_info, database, "mysql"); DBUG_ENTER("dump_all_tables_in_db"); @@ -5333,11 +5381,15 @@ static int dump_all_tables_in_db(char *database) afterdot= strmov(hash_key, database); *afterdot++= '.'; - if (init_dumping(database, init_dumping_tables)) + if (init_dumping(database, using_mysql_db ? init_dumping_mysql_tables + : init_dumping_tables)) DBUG_RETURN(1); if (opt_xml) print_xml_tag(md_result_file, "", "\n", "database", "name=", database, NullS); + if (using_mysql_db) + dump_first_mysql_tables(database); + if (lock_tables) { DYNAMIC_STRING query; @@ -5426,24 +5478,16 @@ static int dump_all_tables_in_db(char *database) else { /* - If general_log and slow_log exists in the 'mysql' database, + If transaction_registry exists in the 'mysql' database, we should dump the table structure. But we cannot call get_table_structure() here as 'LOCK TABLES' query got executed above on the session and that 'LOCK TABLES' query does not contain - 'general_log' and 'slow_log' tables. (you cannot acquire lock - on log tables). Hence mark the existence of these log tables here and + 'transaction_registry'. Hence mark the existence of the table here and after 'UNLOCK TABLES' query is executed on the session, get the table structure from server and dump it in the file. */ - if (using_mysql_db) - { - if (!my_strcasecmp(charset_info, table, "general_log")) - general_log_table_exists= 1; - else if (!my_strcasecmp(charset_info, table, "slow_log")) - slow_log_table_exists= 1; - else if (!my_strcasecmp(charset_info, table, "transaction_registry")) - transaction_registry_table_exists= 1; - } + if (using_mysql_db && !my_strcasecmp(charset_info, table, "transaction_registry")) + transaction_registry_table_exists= 1; } } @@ -5464,39 +5508,25 @@ static int dump_all_tables_in_db(char *database) DBUG_PRINT("info", ("Dumping routines for database %s", database)); dump_routines_for_db(database); } - if (opt_xml) - { - fputs("</database>\n", md_result_file); - check_io(md_result_file); - } if (lock_tables) (void) mysql_query_with_error_report(mysql, 0, "UNLOCK TABLES"); if (using_mysql_db) { - char table_type[NAME_LEN]; - char ignore_flag; - if (general_log_table_exists) - { - if (!get_table_structure((char *) "general_log", - database, table_type, &ignore_flag) ) - verbose_msg("-- Warning: get_table_structure() failed with some internal " - "error for 'general_log' table\n"); - } - if (slow_log_table_exists) - { - if (!get_table_structure((char *) "slow_log", - database, table_type, &ignore_flag) ) - verbose_msg("-- Warning: get_table_structure() failed with some internal " - "error for 'slow_log' table\n"); - } if (transaction_registry_table_exists) { + char table_type[NAME_LEN]; + char ignore_flag; if (!get_table_structure((char *) "transaction_registry", database, table_type, &ignore_flag) ) verbose_msg("-- Warning: get_table_structure() failed with some internal " "error for 'transaction_registry' table\n"); } } + if (opt_xml) + { + fputs("</database>\n", md_result_file); + check_io(md_result_file); + } if (flush_privileges && using_mysql_db) { fprintf(md_result_file,"\n--\n-- Flush Grant Tables \n--\n"); |