mysqldump 只要多加個參數
--skip-extended-insert
就可以例如
# mysqldump test tbl_photo -p -uroot --skip-extended-insert
不知哪一版開始
mysqldump 出來的資料變這樣,每筆都串成一行
(似乎是 5.0 起的改變?!)
# mysqldump test tbl_photo -p -uroot DROP TABLE IF EXISTS `tbl_photo`; CREATE TABLE `tbl_photo` ( `fid` int(4) unsigned NOT NULL AUTO_INCREMENT, `linkid` int(4) unsigned NOT NULL DEFAULT '0', `filename` char(30) DEFAULT NULL, PRIMARY KEY (`fid`), KEY `lid` (`linkid`), KEY `fn` (`filename`) ) ENGINE=MyISAM AUTO_INCREMENT=26850 DEFAULT CHARSET=utf8; -- -- Dumping data for table `tbl_photo` -- LOCK TABLES `tbl_photo` WRITE; /*!40000 ALTER TABLE `tbl_photo` DISABLE KEYS */; INSERT INTO `tbl_photo` VALUES (26839,182,'p182_11867397_86123.jpg'),(26838,182,'p182_11867397_17990.jpg'),(26836,182, 'p182_11867397_94778.jpg'),(26835,182,'p182_11867397_01644.jpg'),(26834,182,'p182_11867397_79122.jpg'),(26840,182,'p18 2_11867398_97204.jpg');
只要多加個參數
--skip-extended-insert
即可每一筆資料都一行 INSERT INTO....
(奇怪的是,這個參數在 --help 裏沒說明,線上文件倒是有說明 )
# mysqldump test tbl_photo -p -uroot --skip-extended-insert DROP TABLE IF EXISTS `tbl_photo`; CREATE TABLE `tbl_photo` ( `fid` int(4) unsigned NOT NULL AUTO_INCREMENT, `linkid` int(4) unsigned NOT NULL DEFAULT '0', `filename` char(30) DEFAULT NULL, PRIMARY KEY (`fid`), KEY `lid` (`linkid`), KEY `fn` (`filename`) ) ENGINE=MyISAM AUTO_INCREMENT=26850 DEFAULT CHARSET=utf8; -- -- Dumping data for table `tbl_photo` -- LOCK TABLES `tbl_photo` WRITE; /*!40000 ALTER TABLE `tbl_photo` DISABLE KEYS */; INSERT INTO `tbl_photo` VALUES (26839,182,'p182_11867397_86123.jpg'); INSERT INTO `tbl_photo` VALUES (26838,182,'p182_11867397_17990.jpg'); INSERT INTO `tbl_photo` VALUES (26836,182,'p182_11867397_94778.jpg'); INSERT INTO `tbl_photo` VALUES (26835,182,'p182_11867397_01644.jpg'); INSERT INTO `tbl_photo` VALUES (26834,182,'p182_11867397_79122.jpg'); INSERT INTO `tbl_photo` VALUES (26840,182,'p182_11867398_97204.jpg');
特別注意
兩種 sql 格式的在匯入 mysql 時 速度有很大、很大、非常大的差異
參考 msyqldump / import 速度