Bug #33543 mysqldump and hotcopy don't escape database names appropriately in use statement
Submitted: 27 Dec 2007 22:16 Modified: 8 Apr 2009 20:03
Reporter: Donovan Jimenez Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S1 (Critical)
Version:5.1.22 OS:Linux
Assigned to: CPU Architecture:Any

[27 Dec 2007 22:16] Donovan Jimenez
Description:
Seems that the ramifications of the new escaping done in 5.1 hasn't been propagated to all the commandline utilities.

Could not find any ways to work around this, so I'm fairly certain its an oversight in the code. Oddly, the mysql shell does not have a problem with a naked use statement - which makes no sense to me either. 

How to repeat:
1. create a database named some_db_with_a-hyphen (or rename some existing test database you have), notice i have to use backticks

mysql>create database `some_db_with_a-hyphen`;

2. Dump the database with mysqldump

# mysqldump -u backup -p -h your_db_server some_db_with_a-hyphen > some_db_with_a-hyphen.sql
Enter password: 
mysqldump: Couldn't execute 'use some_db_with_a-hyphen': You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-hyphen' at line 1 (1064)
[28 Dec 2007 5:11] Valeriy Kravchuk
Thank you for a bug report. Verified just as described.
[19 Aug 2008 12:49] Michael Rack
This error is also existing in MySQL 5.1.21-beta !

Please fix this error before release mysql 5.1 ...

This is very important.
[8 Apr 2009 20:03] Jim Winstead
This bug was a duplicate of Bug #31113, which was fixed in 5.1.23 and 6.0.4. It's not a problem in 5.0 because the bug was introduced in code new to 5.1.