Skip to content

Commit 8ab9b49

Browse files
author
Arun Kuruvila
committed
Bug #25469161: MYSQLDUMP SHOULD EXCLUDE REPLICATION
REPOSITORY METADATA TABLES Description : Replication meta data tables such as mysql.slave_master_info and mysql.slave_relay_log_info gets backed up when MYSQLDUMP is executed. Analysis:- The above mentioned replication tables should be excluded from backups because they are not a logical part of data. These tables contain replication channel meta data that will leave the replication meta data in an invalid state after the restoration of the dump. Fix: Both the tables are excluded from MYSQLDUMP.
1 parent 082ab30 commit 8ab9b49

File tree

4 files changed

+141
-7
lines changed

4 files changed

+141
-7
lines changed

client/mysqldump.c

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,6 +2622,15 @@ static inline my_bool general_log_or_slow_log_tables(const char *db,
26222622
!my_strcasecmp(charset_info, table, "slow_log"));
26232623
}
26242624

2625+
/* slave_master_info and slave_relay_log_info tables under mysql database */
2626+
static inline my_bool replication_metadata_tables(const char *db,
2627+
const char *table)
2628+
{
2629+
return (!my_strcasecmp(charset_info, db, "mysql")) &&
2630+
(!my_strcasecmp(charset_info, table, "slave_master_info") ||
2631+
!my_strcasecmp(charset_info, table, "slave_relay_log_info"));
2632+
}
2633+
26252634
/*
26262635
get_table_structure -- retrievs database structure, prints out corresponding
26272636
CREATE statement and fills out insert_pat if the table is the type we will
@@ -2659,6 +2668,7 @@ static uint get_table_structure(char *table, char *db, char *table_type,
26592668
FILE *sql_file= md_result_file;
26602669
size_t len;
26612670
my_bool is_log_table;
2671+
my_bool is_replication_metadata_table;
26622672
unsigned int colno;
26632673
MYSQL_RES *result;
26642674
MYSQL_ROW row;
@@ -2737,8 +2747,10 @@ static uint get_table_structure(char *table, char *db, char *table_type,
27372747
view-specific code below fills in the DROP VIEW.
27382748
We will skip the DROP TABLE for general_log and slow_log, since
27392749
those stmts will fail, in case we apply dump by enabling logging.
2750+
We will skip this for replication metadata tables as well.
27402751
*/
2741-
if (!general_log_or_slow_log_tables(db, table))
2752+
if (!(general_log_or_slow_log_tables(db, table) ||
2753+
replication_metadata_tables(db, table)))
27422754
fprintf(sql_file, "DROP TABLE IF EXISTS %s;\n",
27432755
opt_quoted_table);
27442756
check_io(sql_file);
@@ -2868,13 +2880,14 @@ static uint get_table_structure(char *table, char *db, char *table_type,
28682880
row= mysql_fetch_row(result);
28692881

28702882
is_log_table= general_log_or_slow_log_tables(db, table);
2871-
if (is_log_table)
2883+
is_replication_metadata_table= replication_metadata_tables(db, table);
2884+
if (is_log_table || is_replication_metadata_table)
28722885
row[1]+= 13; /* strlen("CREATE TABLE ")= 13 */
28732886
if (opt_compatible_mode & 3)
28742887
{
28752888
fprintf(sql_file,
2876-
is_log_table ? "CREATE TABLE IF NOT EXISTS %s;\n" : "%s;\n",
2877-
row[1]);
2889+
(is_log_table || is_replication_metadata_table) ?
2890+
"CREATE TABLE IF NOT EXISTS %s;\n" : "%s;\n", row[1]);
28782891
}
28792892
else
28802893
{
@@ -2883,8 +2896,8 @@ static uint get_table_structure(char *table, char *db, char *table_type,
28832896
"/*!40101 SET character_set_client = utf8 */;\n"
28842897
"%s%s;\n"
28852898
"/*!40101 SET character_set_client = @saved_cs_client */;\n",
2886-
is_log_table ? "CREATE TABLE IF NOT EXISTS " : "",
2887-
row[1]);
2899+
(is_log_table || is_replication_metadata_table) ?
2900+
"CREATE TABLE IF NOT EXISTS " : "", row[1]);
28882901
}
28892902

28902903
check_io(sql_file);
@@ -3622,6 +3635,12 @@ static void dump_table(char *table, char *db)
36223635
if (strcmp(table_type, "VIEW") == 0)
36233636
DBUG_VOID_RETURN;
36243637

3638+
/*
3639+
We don't dump data fo`r replication metadata tables.
3640+
*/
3641+
if (replication_metadata_tables(db, table))
3642+
DBUG_VOID_RETURN;
3643+
36253644
/* Check --no-data flag */
36263645
if (opt_no_data)
36273646
{

mysql-test/r/mysqldump.result

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5589,3 +5589,96 @@ ROUTINE_NAME
55895589
proc
55905590
one
55915591
DROP DATABASE bug25717383;
5592+
#
5593+
# Bug #25469161: MYSQLDUMP SHOULD EXCLUDE REPLICATION
5594+
# REPOSITORY METADATA TABLES
5595+
#
5596+
SHOW VARIABLES LIKE "master_info_repository";
5597+
Variable_name Value
5598+
master_info_repository FILE
5599+
SHOW VARIABLES LIKE "relay_log_info_repository";
5600+
Variable_name Value
5601+
relay_log_info_repository FILE
5602+
SET GLOBAL master_info_repository= 'TABLE';
5603+
SET GLOBAL relay_log_info_repository= 'TABLE';
5604+
SHOW VARIABLES LIKE "master_info_repository";
5605+
Variable_name Value
5606+
master_info_repository TABLE
5607+
SHOW VARIABLES LIKE "relay_log_info_repository";
5608+
Variable_name Value
5609+
relay_log_info_repository TABLE
5610+
5611+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
5612+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
5613+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
5614+
/*!40101 SET NAMES utf8 */;
5615+
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
5616+
/*!40103 SET TIME_ZONE='+00:00' */;
5617+
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
5618+
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
5619+
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
5620+
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
5621+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5622+
/*!40101 SET character_set_client = utf8 */;
5623+
CREATE TABLE IF NOT EXISTS `slave_master_info` (
5624+
`Number_of_lines` int(10) unsigned NOT NULL COMMENT 'Number of lines in the file.',
5625+
`Master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log currently being read from the master.',
5626+
`Master_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The master log position of the last read event.',
5627+
`Host` char(64) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL COMMENT 'The host name of the master.',
5628+
`User_name` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The user name used to connect to the master.',
5629+
`User_password` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The password used to connect to the master.',
5630+
`Port` int(10) unsigned NOT NULL COMMENT 'The network port used to connect to the master.',
5631+
`Connect_retry` int(10) unsigned NOT NULL COMMENT 'The period (in seconds) that the slave will wait before trying to reconnect to the master.',
5632+
`Enabled_ssl` tinyint(1) NOT NULL COMMENT 'Indicates whether the server supports SSL connections.',
5633+
`Ssl_ca` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Authority (CA) certificate.',
5634+
`Ssl_capath` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path to the Certificate Authority (CA) certificates.',
5635+
`Ssl_cert` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL certificate file.',
5636+
`Ssl_cipher` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the cipher in use for the SSL connection.',
5637+
`Ssl_key` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL key file.',
5638+
`Ssl_verify_server_cert` tinyint(1) NOT NULL COMMENT 'Whether to verify the server certificate.',
5639+
`Heartbeat` float NOT NULL,
5640+
`Bind` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'Displays which interface is employed when connecting to the MySQL server',
5641+
`Ignored_server_ids` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The number of server IDs to be ignored, followed by the actual server IDs',
5642+
`Uuid` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The master server uuid.',
5643+
`Retry_count` bigint(20) unsigned NOT NULL COMMENT 'Number of reconnect attempts, to the master, before giving up.',
5644+
`Ssl_crl` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Revocation List (CRL)',
5645+
`Ssl_crlpath` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path used for Certificate Revocation List (CRL) files',
5646+
`Enabled_auto_position` tinyint(1) NOT NULL COMMENT 'Indicates whether GTIDs will be used to retrieve events from the master.',
5647+
`Channel_name` char(64) NOT NULL COMMENT 'The channel on which the slave is connected to a source. Used in Multisource Replication',
5648+
`Tls_version` text CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'Tls version',
5649+
PRIMARY KEY (`Channel_name`)
5650+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='Master Information';
5651+
/*!40101 SET character_set_client = @saved_cs_client */;
5652+
/*!40101 SET @saved_cs_client = @@character_set_client */;
5653+
/*!40101 SET character_set_client = utf8 */;
5654+
CREATE TABLE IF NOT EXISTS `slave_relay_log_info` (
5655+
`Number_of_lines` int(10) unsigned NOT NULL COMMENT 'Number of lines in the file or rows in the table. Used to version table definitions.',
5656+
`Relay_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the current relay log file.',
5657+
`Relay_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The relay log position of the last executed event.',
5658+
`Master_log_name` text CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log file from which the events in the relay log file were read.',
5659+
`Master_log_pos` bigint(20) unsigned NOT NULL COMMENT 'The master log position of the last executed event.',
5660+
`Sql_delay` int(11) NOT NULL COMMENT 'The number of seconds that the slave must lag behind the master.',
5661+
`Number_of_workers` int(10) unsigned NOT NULL,
5662+
`Id` int(10) unsigned NOT NULL COMMENT 'Internal Id that uniquely identifies this record.',
5663+
`Channel_name` char(64) NOT NULL COMMENT 'The channel on which the slave is connected to a source. Used in Multisource Replication',
5664+
PRIMARY KEY (`Channel_name`)
5665+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT='Relay Log Information';
5666+
/*!40101 SET character_set_client = @saved_cs_client */;
5667+
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
5668+
5669+
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
5670+
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
5671+
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
5672+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
5673+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
5674+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
5675+
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
5676+
5677+
SET GLOBAL master_info_repository= 'FILE';
5678+
SET GLOBAL relay_log_info_repository= 'FILE';
5679+
SHOW VARIABLES LIKE "master_info_repository";
5680+
Variable_name Value
5681+
master_info_repository FILE
5682+
SHOW VARIABLES LIKE "relay_log_info_repository";
5683+
Variable_name Value
5684+
relay_log_info_repository FILE

mysql-test/suite/rpl/t/rpl_alter_repository.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ perl;
262262
use strict;
263263
my $outf= $ENV{'OUTF'} or die "OUTF not set";
264264
open(FILE, "$outf") or die("Unable to open $outf: $!\n");
265-
my $count = () = grep(/CREATE TABLE `slave_master_info`/gi,<FILE>);
265+
my $count = () = grep(/CREATE TABLE IF NOT EXISTS `slave_master_info`/gi,<FILE>);
266266
print "- Occurrences: $count\n";
267267
close(FILE);
268268
EOF

mysql-test/t/mysqldump.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,3 +2697,25 @@ SELECT ROUTINE_NAME FROM INFORMATION_SCHEMA.ROUTINES
26972697
ORDER BY ROUTINE_NAME;
26982698

26992699
DROP DATABASE bug25717383;
2700+
2701+
--echo #
2702+
--echo # Bug #25469161: MYSQLDUMP SHOULD EXCLUDE REPLICATION
2703+
--echo # REPOSITORY METADATA TABLES
2704+
--echo #
2705+
2706+
SHOW VARIABLES LIKE "master_info_repository";
2707+
SHOW VARIABLES LIKE "relay_log_info_repository";
2708+
2709+
SET GLOBAL master_info_repository= 'TABLE';
2710+
SET GLOBAL relay_log_info_repository= 'TABLE';
2711+
2712+
SHOW VARIABLES LIKE "master_info_repository";
2713+
SHOW VARIABLES LIKE "relay_log_info_repository";
2714+
2715+
--exec $MYSQL_DUMP --skip-comments mysql slave_master_info slave_relay_log_info 2>&1
2716+
2717+
SET GLOBAL master_info_repository= 'FILE';
2718+
SET GLOBAL relay_log_info_repository= 'FILE';
2719+
2720+
SHOW VARIABLES LIKE "master_info_repository";
2721+
SHOW VARIABLES LIKE "relay_log_info_repository";

0 commit comments

Comments
 (0)