假設要將服務器A上的數據庫test備份到服務器B
1.在服務器B上新建數據庫cp_test
mysql> create database cp_test; Query OK, 1 row affected (0.00 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | cp_test | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec)
mysql>
2.在服務器B上遠程訪問服務器A,並將服務器A上的數據庫備份到服務器B(本人只是作為測試,所以就跳過了鎖表)
執行時間3分鍾
[root@zhangmeng ~]# mysqldump -h192.168.1.1-ubob -p --skip-add-locks test >/root/cp_test.sql Enter password: Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database.
If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events. [root@zhangmeng ~]#
3.大概1165M,備份之間在3分鍾左右
[root@zhangmeng ~]# ll total 1192548 -rw-------. 1 root root 959 Jun 22 11:24 anaconda-ks.cfg -rw-r--r--. 1 root root 1221135418 Aug 18 17:29 cp_test.sql -rw-r--r--. 1 root root 8785 Jun 22 11:24 install.log -rw-r--r--. 1 root root 3161 Jun 22 11:24 install.log.syslog -rw-r--r--. 1 root root 5824 Nov 12 2015 mysql-community-release-el6-5.noarch.rpm
4.將剛才的備份文件還原到服務器B的cp_test庫上
[root@zhangmeng ~]# mysql -f -uroot -p cp_test <cp_test.sql Enter password: ERROR 1839 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_MODE = ON.
5.,提示報錯,上網查資料,加上-f參數雖然報錯,但是仍會執行,其實可以在命令前面加上time,這樣可以准確知道具體執行時間
[root@zhangmeng ~]# mysql -uroot -p test <cp_test.sql Enter password: ERROR 1839 (HY000) at line 24: @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_MODE = ON.
