[root@centos6 ~]# ll /download/ total 14 -rw-r--r--. 1 root root 2027 Dec 12 20:41 testbak_2016-12-12_b.sql -rw-r--r--. 1 root root 1888 Dec 12 20:34 testbak_2016-12-12.sql -rw-r--r--. 1 root root 753 Dec 12 20:49 testbak_2016-12-12.sql.gz 同時也可以看的壓縮后的效果
3、多庫備份 [root@centos6 ~]# mysqldump -uroot -p -B test mysql|gzip >/download/testbak_$(date +%F).sql01.gz Enter password: -- Warning: Skipping the data of table mysql.event. Specify the --events option explicitly.
-- MySQL dump 10.13 Distrib 5.5.52, for linux2.6 (x86_64) -- -- Host: localhost Database: test -- ------------------------------------------------------ -- Server version 5.5.53-log -- -- Current Database: `test` -- USE `test`; -- -- Table structure for table `test` -- DROP TABLE IF EXISTS `test`; CREATE TABLE `test` ( `id` int(4) NOT NULL, `name` char(20) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `test` -- LOCK TABLES `test` WRITE; INSERT INTO `test` VALUES (1,'1'),(11,'text'),(21,'abc'),(9,'bcd'),(111,'1'),(441,'text'),(41,'abc'),(999,'bcd'); UNLOCK TABLES; -- -- Current Database: `test` -- USE `test`; -- -- Table structure for table `test` -- DROP TABLE IF EXISTS `test`; CREATE TABLE `test` ( `id` int(4) NOT NULL, `name` char(20) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `test` -- LOCK TABLES `test` WRITE; INSERT INTO `test` VALUES (1,'1'),(11,'text'),(21,'abc'),(9,'bcd'),(111,'1'),(441,'text'),(41,'abc'),(999,'bcd'); UNLOCK TABLES; -- Dump completed on 2016-12-12 21:13:16 因此分表備份同分庫備份一樣,只需要進行多次單表備份的操作,但是有的小伙伴肯定會提出問題了,如果一個庫里幾千張表,幾萬張表,這種備份要備到猴年馬月吧????,數(shù)據(jù)量比較大的備份可以使用專業(yè)的備份工具,數(shù)據(jù)量不大或者表不是很多的情況,可以將備份操作寫成腳本 納入定時任務,定時執(zhí)行,只需要檢查備份是否成功即可
分享一下民工哥,實際生產(chǎn)環(huán)境中一個簡單的備份腳本,僅供參考 [root@centos6 scripts]# vi bak.sh #!/bin/sh ########################################## #this scripts create by root of mingongge #create at 2016-11-11 #######################################