Bug #71437 dump & restore fails when database name contains '\'
Submitted: 21 Jan 2014 2:12 Modified: 31 Mar 2014 14:18
Reporter: xiaobin lin (OCA) Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1+ OS:Any
Assigned to: CPU Architecture:Any
Tags: mysqldump, SOURCE, Use

[21 Jan 2014 2:12] xiaobin lin
When databasename (such as `a\\k`) contains '\', the syntax when use requires an escaped dbname. It means "use `a\\\\k`" needed, but not "use `a\\k`"

This behavior is not the same with that in normal SQL.
In fact "show tables from `a\\k`" is ok, because the client will escape it to "a\\\\k" before sending. 

But the "USE dbname" command is a bit special.

This will lead to an error when dumping and restoring, as describs follow.

How to repeat:
mysql -Srun/mysql.sock -uroot -e '
create database `a\\k`;
create table `a\\k`.tb(c int);
mysqldump -Srun/mysql.sock -uroot --all-databases -d > schema
mysql -Srun/mysql.sock -uroot -e '
  drop database `a\\k`;
  source ./schema;

Suggested fix:
The error message says "Unknown database 'a\k' ".
It is because there is  "USE `a\\k`" in the result of mysqldump.

So is it a bug about "mysqldump" or  "mysql" client program?

If we treate "USE dbname" as a special command, and "USE a\\\\k" is under designed, then a simple patch against mysqldump can be as follow.
[21 Jan 2014 2:12] xiaobin lin
based on 5.5.18

(*) I confirm the code being submitted is offered under the terms of the OCA, and that I am authorized to contribute it.

Contribution: mysqldump_slash_dbname.diff (application/octet-stream, text), 666 bytes.

[21 Jan 2014 13:16] MySQL Verification Team
Hello Xiaobin,

Thank you for the report and contribution.

[31 Mar 2014 14:18] Paul DuBois
Noted in 5.7.5 changelog.

For mysqldump, dump and restore operations failed for database names
that contained backslash ('\'). Thanks for Xiaobin Lin for the patch.