Home | Mirror | Search

2. mysqldump - a database backup program

		
mysqldump -uroot -p dbname | gzip > dbname.backup
		
		

2.1. 備份資料庫,無結構,只有數據

-t, --no-create-info Don't write table creation info.

mysqldump -uroot -p -t -d database
			

2.2. 備份資料庫結構(不備份數據)

mysqldump -uroot -p -d database
mysqldump -uroot -p -d database table
			

2.3. 使用完整的insert插入數據

-c, --complete-insert Use complete insert statements.

$ mysqldump -hlocalhost -uroot -t neo test

INSERT INTO `test` VALUES (98,'neo','chen'),(112,'jam','zheng'),(113,'john','meng');

$ mysqldump -hlocalhost -uroot -c -t neo test
INSERT INTO `test` (`userid`, `username`, `password`) VALUES (98,'neo','chen'),(112,'jam','zheng'),(113,'john','meng');
			

2.4. --extended-insert / --skip-extended-insert

--extended-insert 預設開啟

INSERT INTO `test` VALUES (98,'neo','chen'),(112,'jam','zheng'),(113,'john','meng');
			

每條記錄使用一次insert

$ mysqldump -hlocalhost -uroot --skip-extended-insert -t neo test |more
INSERT INTO `test` VALUES (98,'neo','chen');
INSERT INTO `test` VALUES (111,'neo','chen');
INSERT INTO `test` VALUES (112,'jam','zheng');
INSERT INTO `test` VALUES (113,'john','meng');
			

2.5. --where

mysqldump -hlocalhost -umysql -ppasswd database table --where="id>128"
			
comments powered by Disqus