summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorDaniel Black <daniel@mariadb.org>2022-05-06 17:44:33 +1000
committerDaniel Black <daniel@mariadb.org>2022-05-06 22:50:01 +1000
commit221ced92aa02d42d26a5a4945a0e90ba5dcbcbfa (patch)
treeba171be863b9ab944a3bf785168ce1615a6f9003 /client
parent9fe3bc2aa881118def3987358935e77c39b9fdb8 (diff)
downloadmariadb-git-221ced92aa02d42d26a5a4945a0e90ba5dcbcbfa.tar.gz
MDEV-4875 Can't restore a mysqldump if --add-drop-database meets general_log
or slow query log when the log_output=TABLE. When this happens, we temporary disable by changing log_output until we've created the general_log and slow_log tables again. Move </database> in xml mode until after the transaction_registry. General_log and slow_log tables where moved to be first to be dumped so that the disabling of the general/slow queries is minimal.
Diffstat (limited to 'client')
-rw-r--r--client/mysqldump.c100
1 files changed, 65 insertions, 35 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c
index 991c3f528b4..6cdc3db3c08 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -5230,6 +5230,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
@@ -5335,7 +5384,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");
@@ -5343,11 +5391,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;
@@ -5436,24 +5488,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;
}
}
@@ -5474,39 +5518,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");