Description:
mysqldump events and routines will be error when database name include ' character.
mysqld reports like this: Couldn't execute 'use `\'test`': Unknown database '\'test' (1049)
because function mysql_real_escape_string add '\\' before '\''character.
How to repeat:
mysql> create database `'test`;
Query OK, 1 row affected (0.00 sec)
mysql> create table `'test`.t1(id int);
Query OK, 0 rows affected (0.00 sec)
mysql> use `'test`
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> delimiter //
mysql> create procedure pload()
-> begin
-> select * from t1;
-> end
-> //
Query OK, 0 rows affected (0.00 sec)
mysql> delimiter ;
shell# bin/mysqldump -S /tmp/mysql_3306.sock -uroot -R "'test"
or
shell# bin/mysqldump -S /tmp/mysql_3306.sock -uroot -R --all-databases
--
-- Dumping routines for database ''test'
--
mysqldump: Couldn't execute 'use `\'test`': Unknown database '\'test' (1049)
Suggested fix:
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -2344,7 +2345,7 @@ static uint dump_events_for_db(char *db)
/* Get database collation. */
- if (fetch_db_collation(db_name_buff, db_cl_name, sizeof (db_cl_name)))
+ if (fetch_db_collation(db, db_cl_name, sizeof (db_cl_name)))
DBUG_RETURN(1);
}
@@ -2549,7 +2550,7 @@ static uint dump_routines_for_db(char *db)
/* Get database collation. */
- if (fetch_db_collation(db_name_buff, db_cl_name, sizeof (db_cl_name)))
+ if (fetch_db_collation(db, db_cl_name, sizeof (db_cl_name)))
DBUG_RETURN(1);
if (switch_character_set_results(mysql, "binary"))