Commit e88121ea authored by unknown's avatar unknown

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
...@@ -417,7 +417,9 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row, ...@@ -417,7 +417,9 @@ static void print_value(FILE *file, MYSQL_RES *result, MYSQL_ROW row,
int string_value); int string_value);
static int dump_selected_tables(char *db, char **table_names, int tables); static int dump_selected_tables(char *db, char **table_names, int tables);
static int dump_all_tables_in_db(char *db); 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_databases(char **);
static int dump_all_databases(); static int dump_all_databases();
static char *quote_name(const char *name, char *buff, my_bool force); static char *quote_name(const char *name, char *buff, my_bool force);
...@@ -2635,7 +2637,76 @@ static int dump_databases(char **db_names) ...@@ -2635,7 +2637,76 @@ static int dump_databases(char **db_names)
} /* dump_databases */ } /* dump_databases */
static int init_dumping(char *database) /*
View Specific database initalization.
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 */
/*
Table Specific database initalization.
SYNOPSIS
init_dumping_tables
qdatabase quoted name of the database
RETURN VALUES
0 Success.
1 Failure.
*/
int init_dumping_tables(char *qdatabase)
{
if (!opt_create_db)
{
char qbuf[256];
MYSQL_ROW row;
MYSQL_RES *dbinfo;
my_snprintf(qbuf, sizeof(qbuf),
"SHOW CREATE DATABASE IF NOT EXISTS %s",
qdatabase);
if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql)))
{
/* Old server version, dump generic CREATE DATABASE */
if (opt_drop_database)
fprintf(md_result_file,
"\n/*!40000 DROP DATABASE IF EXISTS %s;*/\n",
qdatabase);
fprintf(md_result_file,
"\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n",
qdatabase);
}
else
{
if (opt_drop_database)
fprintf(md_result_file,
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
qdatabase);
row = mysql_fetch_row(dbinfo);
if (row[1])
{
fprintf(md_result_file,"\n%s;\n",row[1]);
}
}
}
return 0;
} /* init_dumping_tables */
static int init_dumping(char *database, int init_func(char*))
{ {
if (mysql_get_server_version(mysql) >= 50003 && if (mysql_get_server_version(mysql) >= 50003 &&
!my_strcasecmp(&my_charset_latin1, database, "information_schema")) !my_strcasecmp(&my_charset_latin1, database, "information_schema"))
...@@ -2660,40 +2731,10 @@ static int init_dumping(char *database) ...@@ -2660,40 +2731,10 @@ static int init_dumping(char *database)
fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase); fprintf(md_result_file,"\n--\n-- Current Database: %s\n--\n", qdatabase);
check_io(md_result_file); check_io(md_result_file);
} }
if (!opt_create_db)
{
char qbuf[256];
MYSQL_ROW row;
MYSQL_RES *dbinfo;
my_snprintf(qbuf, sizeof(qbuf), /* Call the view or table specific function */
"SHOW CREATE DATABASE IF NOT EXISTS %s", init_func(qdatabase);
qdatabase);
if (mysql_query(mysql, qbuf) || !(dbinfo = mysql_store_result(mysql)))
{
/* Old server version, dump generic CREATE DATABASE */
if (opt_drop_database)
fprintf(md_result_file,
"\n/*!40000 DROP DATABASE IF EXISTS %s;*/\n",
qdatabase);
fprintf(md_result_file,
"\nCREATE DATABASE /*!32312 IF NOT EXISTS*/ %s;\n",
qdatabase);
}
else
{
if (opt_drop_database)
fprintf(md_result_file,
"\n/*!40000 DROP DATABASE IF EXISTS %s*/;\n",
qdatabase);
row = mysql_fetch_row(dbinfo);
if (row[1])
{
fprintf(md_result_file,"\n%s;\n",row[1]);
}
}
}
fprintf(md_result_file,"\nUSE %s;\n", qdatabase); fprintf(md_result_file,"\nUSE %s;\n", qdatabase);
check_io(md_result_file); check_io(md_result_file);
} }
...@@ -2725,7 +2766,7 @@ static int dump_all_tables_in_db(char *database) ...@@ -2725,7 +2766,7 @@ static int dump_all_tables_in_db(char *database)
afterdot= strmov(hash_key, database); afterdot= strmov(hash_key, database);
*afterdot++= '.'; *afterdot++= '.';
if (init_dumping(database)) if (init_dumping(database, init_dumping_tables))
return 1; return 1;
if (opt_xml) if (opt_xml)
print_xml_tag1(md_result_file, "", "database name=", database, "\n"); print_xml_tag1(md_result_file, "", "database name=", database, "\n");
...@@ -2797,23 +2838,8 @@ static my_bool dump_all_views_in_db(char *database) ...@@ -2797,23 +2838,8 @@ static my_bool dump_all_views_in_db(char *database)
uint numrows; uint numrows;
char table_buff[NAME_LEN*2+3]; char table_buff[NAME_LEN*2+3];
if (mysql_select_db(mysql, database)) if (init_dumping(database, init_dumping_views))
{
DB_error(mysql, "when selecting the database");
return 1; 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) if (opt_xml)
print_xml_tag1(md_result_file, "", "database name=", database, "\n"); print_xml_tag1(md_result_file, "", "database name=", database, "\n");
if (lock_tables) if (lock_tables)
...@@ -2908,7 +2934,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables) ...@@ -2908,7 +2934,7 @@ static int dump_selected_tables(char *db, char **table_names, int tables)
char **dump_tables, **pos, **end; char **dump_tables, **pos, **end;
DBUG_ENTER("dump_selected_tables"); DBUG_ENTER("dump_selected_tables");
if (init_dumping(db)) if (init_dumping(db, init_dumping_tables))
return 1; return 1;
init_alloc_root(&root, 8192, 0); init_alloc_root(&root, 8192, 0);
......
...@@ -2892,3 +2892,17 @@ CREATE TABLE `t1` ( ...@@ -2892,3 +2892,17 @@ CREATE TABLE `t1` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1; ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
drop table t1; drop table t1;
drop user mysqltest_1@localhost; 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;
...@@ -1309,3 +1309,33 @@ grant REPLICATION CLIENT on *.* to mysqltest_1@localhost; ...@@ -1309,3 +1309,33 @@ grant REPLICATION CLIENT on *.* to mysqltest_1@localhost;
# Clean up # Clean up
drop table t1; drop table t1;
drop user mysqltest_1@localhost; 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;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment