Commit e88121ea authored by unknown's avatar unknown
Browse files

Bug #21527 mysqldump incorrectly tries to LOCK TABLES on the information_schema database.

    
init_dumping now accepts a function pointer to the table or view specific init_dumping function.  This allows both tables and views to use the init_dumping function.


client/mysqldump.c:
  Added functions for table and view specific dumping initalization.
mysql-test/r/mysqldump.result:
  Added Result.
mysql-test/t/mysqldump.test:
  Added test case.
parent 3f53d3d5
Loading
Loading
Loading
Loading
+78 −52
Original line number Diff line number Diff line
@@ -417,7 +417,9 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
                        int string_value);
static int dump_selected_tables(char *db, char **table_names, int tables);
static int dump_all_tables_in_db(char *db);
static int init_dumping(char *);
static int init_dumping_views(char *);
static int init_dumping_tables(char *);
static int init_dumping(char *, int init_func(char*));
static int dump_databases(char **);
static int dump_all_databases();
static char *quote_name(const char *name, char *buff, my_bool force);
@@ -2635,31 +2637,36 @@ static int dump_databases(char **db_names)
} /* dump_databases */


static int init_dumping(char *database)
{
  if (mysql_get_server_version(mysql) >= 50003 &&
      !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
    return 1;
/*
View Specific database initalization.

  if (mysql_select_db(mysql, database))
  {
    DB_error(mysql, "when selecting the database");
    return 1;                   /* If --force */
  }
  if (!path && !opt_xml)
  {
    if (opt_databases || opt_alldbs)
SYNOPSIS
  init_dumping_views
  qdatabase      quoted name of the database

RETURN VALUES
  0        Success.
  1        Failure.
*/
int init_dumping_views(char *qdatabase)
{
    return 0;
} /* init_dumping_views */


/*
        length of table name * 2 (if name contains quotes), 2 quotes and 0
Table Specific database initalization.

SYNOPSIS
  init_dumping_tables
  qdatabase      quoted name of the database

RETURN VALUES
  0        Success.
  1        Failure.
*/
      char quoted_database_buf[NAME_LEN*2+3];
      char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
      if (opt_comments)
int init_dumping_tables(char *qdatabase)
{
        fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase);
        check_io(md_result_file);
      }
  if (!opt_create_db)
  {
    char qbuf[256];
@@ -2694,6 +2701,40 @@ static int init_dumping(char *database)
      }
    }
  }

  return 0;
} /* init_dumping_tables */


static int init_dumping(char *database, int init_func(char*))
{
  if (mysql_get_server_version(mysql) >= 50003 &&
      !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
    return 1;

  if (mysql_select_db(mysql, database))
  {
    DB_error(mysql, "when selecting the database");
    return 1;                   /* If --force */
  }
  if (!path && !opt_xml)
  {
    if (opt_databases || opt_alldbs)
    {
      /*
        length of table name * 2 (if name contains quotes), 2 quotes and 0
      */
      char quoted_database_buf[NAME_LEN*2+3];
      char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
      if (opt_comments)
      {
        fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase);
        check_io(md_result_file);
      }

      /* Call the view or table specific function */
      init_func(qdatabase);

      fprintf(md_result_file,"\nUSE %s;\n", qdatabase);
      check_io(md_result_file);
    }
@@ -2725,7 +2766,7 @@ static int dump_all_tables_in_db(char *database)
  afterdot= strmov(hash_key, database);
  *afterdot++= '.';

  if (init_dumping(database))
  if (init_dumping(database, init_dumping_tables))
    return 1;
  if (opt_xml)
    print_xml_tag1(md_result_file, "", "database name=", database, "\n");
@@ -2797,23 +2838,8 @@ static my_bool dump_all_views_in_db(char *database)
  uint numrows;
  char table_buff[NAME_LEN*2+3];

  if (mysql_select_db(mysql, database))
  {
    DB_error(mysql, "when selecting the database");
  if (init_dumping(database, init_dumping_views))
    return 1;
  }
  if (opt_databases || opt_alldbs)
  {
    char quoted_database_buf[NAME_LEN*2+3];
    char *qdatabase= quote_name(database,quoted_database_buf,opt_quoted);
    if (opt_comments)
    {
      fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase);
      check_io(md_result_file);
    }
    fprintf(md_result_file,"\nUSE %s;\n", qdatabase);
    check_io(md_result_file);
  }
  if (opt_xml)
    print_xml_tag1(md_result_file, "", "database name=", database, "\n");
  if (lock_tables)
@@ -2908,7 +2934,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
  char **dump_tables, **pos, **end;
  DBUG_ENTER("dump_selected_tables");

  if (init_dumping(db))
  if (init_dumping(db, init_dumping_tables))
    return 1;

  init_alloc_root(&root, 8192, 0);
+14 −0
Original line number Diff line number Diff line
@@ -2892,3 +2892,17 @@ CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
drop table t1;
drop user mysqltest_1@localhost;
create database mysqldump_myDB;
use mysqldump_myDB;
create user myDB_User;
grant create view, select on mysqldump_myDB.* to myDB_User@localhost;
create table t1 (c1 int);
insert into t1 values (3);
use mysqldump_myDB;
create view v1 (c1) as select * from t1;
use mysqldump_myDB;
drop view v1;
drop table t1;
revoke all privileges on mysqldump_myDB.* from myDB_User@localhost;
drop user myDB_User;
drop database mysqldump_myDB;
+30 −0
Original line number Diff line number Diff line
@@ -1309,3 +1309,33 @@ grant REPLICATION CLIENT on *.* to mysqltest_1@localhost;
# Clean up
drop table t1;
drop user mysqltest_1@localhost;

#
# Bug #21527 mysqldump incorrectly tries to LOCK TABLES on the 
# information_schema database.
#
connect (root,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
connection root;
create database mysqldump_myDB;
use mysqldump_myDB;
create user myDB_User;
grant create view, select on mysqldump_myDB.* to myDB_User@localhost;
create table t1 (c1 int);
insert into t1 values (3);

connect (user1,localhost,myDB_User,,mysqldump_myDB,$MASTER_MYPORT,$MASTER_MYSOCK);
connection user1;
use mysqldump_myDB;
create view v1 (c1) as select * from t1;

# Backup should not fail.
--exec $MYSQL_DUMP --all-databases --add-drop-table > $MYSQLTEST_VARDIR/tmp/bug21527.sql

# Clean up
connection root;
use mysqldump_myDB;
drop view v1;
drop table t1;
revoke all privileges on mysqldump_myDB.* from myDB_User@localhost;
drop user myDB_User;
drop database mysqldump_myDB;