Bug #24337 Mysqldump '--add-drop-database' incorrect statement
Submitted: 15 Nov 2006 15:55 Modified: 21 Nov 2006 16:27
Reporter: Kees Hoekzema Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: mysqldump Command-line Client Severity:S3 (Non-critical)
Version:4.1.21 OS:Linux (Linux 2.6.18.1)
Assigned to: CPU Architecture:Any

[15 Nov 2006 15:55] Kees Hoekzema
Description:
Very similair to: http://bugs.mysql.com/bug.php?id=13700

mysqldump \
    --no-autocommit --no-data --create-options --quote-names \
    --quick --flush-logs --extended-insert --allow-keywords \
    --force --disable-keys --host=${HOST} --user=${USER} \
    --password=${PASS} --add-drop-database --databases ${db}

results in (using db=serverbheer in this example):
[snip]

/*!40000 DROP DATABASE IF EXISTS `serverbeheer`;*/

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `serverbeheer`;

[snip]

Trying to import those statements will result in a:
ERROR 1064 (42000) at line 15: 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 '*/
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `serverbeheer`' at line 1

This is using:
mysqldump  Ver 10.9 Distrib 4.1.21, for unknown-linux-gnu (x86_64)
mysql  Ver 14.7 Distrib 4.1.21, for unknown-linux-gnu (x86_64) using readline 4.3
mysqld  Ver 4.1.21-standard-log for unknown-linux-gnu on x86_64 (MySQL Community Edition - Standard (GPL))

How to repeat:
See above

Suggested fix:
the line
/*!40000 DROP DATABASE IF EXISTS `serverbeheer`;*/

should read
/*!40000 DROP DATABASE IF EXISTS `serverbeheer`*/;

(the ';' should be last, not the */)

Dirty fix: dont use --add-drop-database, make sure you know what databases need to be dropped and do it yourself
[21 Nov 2006 16:27] Valeriy Kravchuk
Thank you for a problem report. Sorry, but I was not able to repeat the behaviour described with latest 4.1.23-BK on Linux:

openxs@suse:~/dbs/4.1> bin/mysqldump --no-autocommit --no-data --create-options
 --quote-names     --quick --flush-logs --extended-insert --allow-keywords
--force --disable-keys --user=root --add-drop-database --databases test | more
-- MySQL dump 10.9
--
-- Host: localhost    Database: test
-- ------------------------------------------------------
-- Server version       4.1.23

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES 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' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Current Database: `test`
--

/*!40000 DROP DATABASE IF EXISTS `test`*/;

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `test` /*!40100 DEFAULT CHARACTER SET l
atin1 */;

So, looks like this bug is already fixed.