summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/mysqldump.c4
-rw-r--r--mysql-test/r/mysqldump.result19
-rw-r--r--mysql-test/t/mysqldump.test12
3 files changed, 34 insertions, 1 deletions
diff --git a/client/mysqldump.c b/client/mysqldump.c
index d504d177490..f5362b272cd 100644
--- a/client/mysqldump.c
+++ b/client/mysqldump.c
@@ -1040,8 +1040,10 @@ static int fetch_db_collation(const char *db_name,
char query[QUERY_LENGTH];
MYSQL_RES *db_cl_res;
MYSQL_ROW db_cl_row;
+ char quoted_database_buf[NAME_LEN*2+3];
+ char *qdatabase= quote_name(db_name, quoted_database_buf, 1);
- my_snprintf(query, sizeof (query), "use %s", db_name);
+ my_snprintf(query, sizeof (query), "use %s", qdatabase);
if (mysql_query_with_error_report(mysql, NULL, query))
return 1;
diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result
index c0856314ba5..d07aed5317a 100644
--- a/mysql-test/r/mysqldump.result
+++ b/mysql-test/r/mysqldump.result
@@ -4212,5 +4212,24 @@ TRUNCATE mysql.event;
SHOW EVENTS;
Db Name Definer Time zone Type Execute at Interval value Interval field Starts Ends Status Originator character_set_client collation_connection Database Collation
#
+# Bug#31113 mysqldump 5.1 can't handle a dash ("-") in database names
+#
+create database `test-database`;
+use `test-database`;
+create table test (a int);
+DROP TABLE IF EXISTS `test`;
+SET @saved_cs_client = @@character_set_client;
+SET character_set_client = utf8;
+CREATE TABLE `test` (
+ `a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1;
+SET character_set_client = @saved_cs_client;
+LOCK TABLES `test` WRITE;
+/*!40000 ALTER TABLE `test` DISABLE KEYS */;
+/*!40000 ALTER TABLE `test` ENABLE KEYS */;
+UNLOCK TABLES;
+drop database `test-database`;
+use test;
+#
# End of 5.1 tests
#
diff --git a/mysql-test/t/mysqldump.test b/mysql-test/t/mysqldump.test
index 158e8a769bd..0e4e9989ffa 100644
--- a/mysql-test/t/mysqldump.test
+++ b/mysql-test/t/mysqldump.test
@@ -1788,6 +1788,18 @@ TRUNCATE mysql.event;
--exec $MYSQL < $MYSQLTEST_VARDIR/tmp/bug29938.sql
SHOW EVENTS;
+
+--echo #
+--echo # Bug#31113 mysqldump 5.1 can't handle a dash ("-") in database names
+--echo #
+create database `test-database`;
+use `test-database`;
+create table test (a int);
+--exec $MYSQL_DUMP --compact --opt --quote-names test-database
+drop database `test-database`;
+use test;
+
+
--echo #
--echo # End of 5.1 tests
--echo #