Anna Adamchuk
Anna Adamchuk

Reputation: 720

mysqldump skip comments

I do database dump with mysqldump command. Command that I use:

$mysqldump -uuser -ppassword --host=1.1.1.1 db_name
--add-drop-database --add-drop-table --skip-compact --no-data
--skip-comments --skip-set-charset --skip-dump-date --skip-tz-utc --tab=path

and get result:

/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
DROP TABLE IF EXISTS `action`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `action` (
  `id` tinyint(4) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;


/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

But I need this dump:

DROP TABLE IF EXISTS `action`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `action` (
  `id` tinyint(4) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

how to remove those comments:

/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
...
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

Upvotes: 0

Views: 6950

Answers (2)

miken32
miken32

Reputation: 42680

For the record, the --compact option will remove these comments. You could have used this command:

mysqldump -uuser -ppassword --host=1.1.1.1 db_name --compact --add-drop-table --no-data

Complete sample output:

DROP TABLE IF EXISTS `tester`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `tester` (
  `col1` varchar(16) DEFAULT NULL,
  `col2` varchar(16) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;

Upvotes: 2

Dmitry Sadakov
Dmitry Sadakov

Reputation: 2158

You can use a post-process Regex to remove the lines since mysqldump does not support removing those comments:

(.*OLD_SQ.*)

with global modifier g.

Upvotes: 1

Related Questions