2016-02-26 60 views
0

我用mysqldump命令做數據庫轉儲。命令我使用:mysqldump跳過評論

$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 

,並得到結果:

/*!40101 SET @[email protected]@SQL_MODE, SQL_MODE='' */; 
/*!40111 SET @[email protected]@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 [email protected]_SQL_MODE */; 
/*!40111 SET [email protected]_SQL_NOTES */; 

但我需要這個轉儲:

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 @[email protected]@SQL_MODE, SQL_MODE='' */; 
/*!40111 SET @[email protected]@SQL_NOTES, SQL_NOTES=0 */; 
... 
/*!40101 SET [email protected]_SQL_MODE */; 
/*!40111 SET [email protected]_SQL_NOTES */; 
+0

他們不是無用的評論 - DUP http://stackoverflow.com/questions/1916392/how-can-i-擺脫這些評論在一個mysql轉儲 – cDima

+0

我已經閱讀了這個問題和答案。但是,無論如何,我必須刪除這些意見 –

+0

可能的重複:http://stackoverflow.com/questions/1916392/how-can-i-get-rid-of-these-comments-in-a-mysql-dump – MaxU

回答

1

你可以使用post-process Regex刪除已經因爲mysqldump的不支持刪除這些評論的線路:

(.*OLD_SQ.*)

全球改性劑g

0

根據記錄,--compact選項將刪除這些評論。你也可以使用這個命令:

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

完整的示例輸出:

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 */;