Bug #2592 mysqldump doesn't quote "tricky" names correctly.
Submitted: 30 Jan 2004 18:39 Modified: 10 Feb 2004 9:22
Reporter: Paul DuBois Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S3 (Non-critical)
Version:4.1 OS:
Assigned to: Bugs System CPU Architecture:Any

[30 Jan 2004 18:39] Paul DuBois
Description:
You can create a table name with a backtick
in it like this:

mysql> create table ```a` (i int);
Query OK, 0 rows affected (0.37 sec)

mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| `a             |
+----------------+
1 row in set (0.00 sec)

But mysqldump won't dump it properly:

% mysqldump --no-data test
-- MySQL dump 10.5
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version       4.1.2-alpha-debug-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT, 
CHARACTER_SET_CLIENT=utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 
*/;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=NO_AUTO_VALUE_ON_ZERO */;
mysqldump: Got error: 1064: 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 ' READ /
*!32311 LOCAL */' at line 1 when using LOCK TABLES

The query that was sent to the server by mysqldump is:

LOCK TABLES ``a` READ /*!32311 LOCAL */

How to repeat:
See above.

Suggested fix:
Not sure. I thought it might be:

--- mysqldump.c.orig    Tue Jan 20 10:51:35 2004
+++ mysqldump.c Fri Jan 30 20:27:46 2004
@@ -649,7 +649,7 @@
   while (*name)
   {
     if (*name == QUOTE_CHAR)
-      *to= QUOTE_CHAR;
+      *to++= QUOTE_CHAR;
     *to++= *name++;
   }
   to[0]=QUOTE_CHAR;

However, although that seems to cause the
generated statement to be correct:

LOCK TABLES ```a` READ /*!32311 LOCAL */

It still results in a syntax error when mysqldump
sends it to the server:

% mysqldump --no-data test
-- MySQL dump 10.5
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version       4.1.2-alpha-debug-log

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT, 
CHARACTER_SET_CLIENT=utf8 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 
*/;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=NO_AUTO_VALUE_ON_ZERO */;
mysqldump: Got error: 1103: Incorrect table name '' when using LOCK TABLES

I don't understand that, because if I copy and paste the query
from the log into the mysql client, the statement *works*.

???
[6 Feb 2004 10:35] Victor Vagin
Thank you very much for your description

You can have a look at commit with subj 
"bk commit - 4.1 tree (vva:1.1688)"

The extra reason of bug was wrong processing of quted names in lexer for multibyte strings (mysqldump connects to server with utf8 by default now)

Please note, final output of test in commit is still wrong because of bug #2593 it will be fixed when patch for bug #2593 will be pushed
[10 Feb 2004 9:22] Victor Vagin
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html