数据库
首页 > 数据库> > 【MySQL】通过Percona XtraBackup实现数据库单表恢复

【MySQL】通过Percona XtraBackup实现数据库单表恢复

作者:互联网

[mysql@wallet01 ~]$ ssh-keygen
[mysql@wallet01 ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub mysql@wallet02

[mysql@wallet01 ~]$ xtrabackup --backup --user=xtrabackup --password=xtrabackup --stream=tar | ssh mysql@wallet02 \ "gzip >/home/mysql/backup/`date '+%Y-%m-%d_%H-%M-%S'`.tar.gz"

[mysql@wallet01 ~]$ mysqldump -uroot -p --no-data --set-gtid-purged=off --databases soe > soe.sql 
Enter password: 

[mysql@wallet01 ~]$ scp soe.sql mysql@wallet02:/home/mysql/


[mysql@wallet02 ~]$ xtrabackup --prepare --export --target-dir=/home/mysql/backup

[mysql@wallet02 ~]$ mysql -uroot -pabcd.1234
mysql> source soe.sql

mysql> select count(*) from soe.customer;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

mysql> set foreign_key_checks=0;
Query OK, 0 rows affected (0.00 sec)

mysql> alter table soe.customer discard tablespace;
Query OK, 0 rows affected (0.06 sec)

[mysql@wallet03 ~]$ scp /home/mysql/backup/soe/customer.cfg /var/lib/mysql/soe/
[mysql@wallet03 ~]$ scp /home/mysql/backup/soe/customer.ibd /var/lib/mysql/soe/

mysql> alter table soe.customer import tablespace;
Query OK, 0 rows affected (2.58 sec)

mysql> select count(*) from soe.customer;
+----------+
| count(*) |
+----------+
|   300000 |
+----------+
1 row in set (0.09 sec)

标签:customer,soe,--,MySQL,XtraBackup,+----------+,Percona,mysql,home
来源: https://blog.51cto.com/u_13598811/2908249