您好,登錄后才能下訂單哦!
參考實現:
https://www.percona.com/doc/percona-xtrabackup/LATEST/innobackupex/innobackupex_script.html
Restoring Individual Tables #5.6之前是不支持的; In server versions prior to 5.6, it is not possible to copy tables between servers by copying the files, even with innodb_file_per_table. However, with the Percona XtraBackup, you can export individual tables from any InnoDB database, and import them into Percona Server with XtraDB or MySQL 5.6 (The source doesn’t have to be XtraDB or or MySQL 5.6, but the destination does). This only works on individual .ibd files, and cannot export a table that is not contained in its own .ibd file.
數據備份:
[root@centos7x ~]$systemctl start mariadb [root@centos7x ~]$mysql < hellodb_InnoDB.sql 默認的每個表一個文件; [root@centos7x ~]$ll /var/lib/mysql/ total 122936 -rw-rw---- 1 mysql mysql 16384 Feb 25 16:11 aria_log.00000001 -rw-rw---- 1 mysql mysql 52 Feb 25 16:11 aria_log_control -rw-rw---- 1 mysql mysql 5 Feb 25 16:18 centos7x.pid drwx------ 2 mysql mysql 272 Feb 25 16:18 hellodb -rw-rw---- 1 mysql mysql 2795 Feb 25 16:11 ib_buffer_pool -rw-rw---- 1 mysql mysql 12582912 Feb 25 16:18 ibdata1 -rw-rw---- 1 mysql mysql 50331648 Feb 25 16:18 ib_logfile0 -rw-rw---- 1 mysql mysql 50331648 Feb 25 16:11 ib_logfile1 -rw-rw---- 1 mysql mysql 12582912 Feb 25 16:18 ibtmp1 -rw-rw---- 1 mysql mysql 0 Feb 25 16:18 multi-master.info drwx--x--x 2 mysql mysql 4096 Feb 25 16:11 mysql srwxrwxrwx 1 mysql mysql 0 Feb 25 16:18 mysql.sock drwx------ 2 mysql mysql 20 Feb 25 16:11 performance_schema -rw-rw---- 1 mysql mysql 24576 Feb 25 16:18 tc.log drwxr-xr-x 2 mysql mysql 6 Feb 25 16:11 test [root@centos7x ~]$ll /var/lib/mysql/hellodb/ total 704 -rw-rw---- 1 mysql mysql 1277 Feb 25 16:18 classes.frm -rw-rw---- 1 mysql mysql 98304 Feb 25 16:18 classes.ibd -rw-rw---- 1 mysql mysql 976 Feb 25 16:18 coc.frm -rw-rw---- 1 mysql mysql 98304 Feb 25 16:18 coc.ibd -rw-rw---- 1 mysql mysql 1251 Feb 25 16:18 courses.frm -rw-rw---- 1 mysql mysql 98304 Feb 25 16:18 courses.ibd -rw-rw---- 1 mysql mysql 61 Feb 25 16:18 db.opt -rw-rw---- 1 mysql mysql 1001 Feb 25 16:18 scores.frm -rw-rw---- 1 mysql mysql 98304 Feb 25 16:18 scores.ibd -rw-rw---- 1 mysql mysql 1208 Feb 25 16:18 students.frm -rw-rw---- 1 mysql mysql 98304 Feb 25 16:18 students.ibd -rw-rw---- 1 mysql mysql 1298 Feb 25 16:18 teachers.frm -rw-rw---- 1 mysql mysql 98304 Feb 25 16:18 teachers.ibd -rw-rw---- 1 mysql mysql 973 Feb 25 16:18 toc.frm -rw-rw---- 1 mysql mysql 98304 Feb 25 16:18 toc.ibd [root@centos7x ~]$mkdir -pv /backups mkdir: created directory ‘/backups’ [root@centos7x ~]$innobackupex --include='hellodb.students' /backups/ 這只是備份了數據了; [root@centos7x ~]$ll /backups/2018-02-25_16-23-08/hellodb/ total 100 -rw-r----- 1 root root 1208 Feb 25 16:23 students.frm -rw-r----- 1 root root 98304 Feb 25 16:23 students.ibd
備份表定義:
所以需要將表定義也導出來;否則將來的恢復過程是需要創建表定義的; [root@centos7x ~]$mysql -e 'show create table hellodb.students\G;' *************************** 1. row *************************** Table: students Create Table: CREATE TABLE `students` ( `StuID` int(10) unsigned NOT NULL AUTO_INCREMENT, `Name` varchar(50) NOT NULL, `Age` tinyint(3) unsigned NOT NULL, `Gender` enum('F','M') NOT NULL, `ClassID` tinyint(3) unsigned DEFAULT NULL, `TeacherID` int(10) unsigned DEFAULT NULL, PRIMARY KEY (`StuID`) ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8
表破壞操作:
進行表的破壞; [root@centos7x ~]$mysql -e 'drop table hellodb.students;' MariaDB [hellodb]> show tables; +-------------------+ | Tables_in_hellodb | +-------------------+ | classes | | coc | | courses | | scores | | teachers | | toc | +-------------------+ 6 rows in set (0.00 sec)
數據和表定義恢復操作:
恢復操作: 先整理; [root@centos7x ~]$innobackupex --apply-log --export /backups/2018-02-25_16-23-08/ 整理、導出數據的前后變化; [root@centos7x ~]$ll /backups/2018-02-25_16-23-08/hellodb/ -rw-r----- 1 root root 1208 Feb 25 16:23 students.frm -rw-r----- 1 root root 98304 Feb 25 16:23 students.ibd [root@centos7x ~]$ll /backups/2018-02-25_16-23-08/hellodb/ total 120 -rw-r--r-- 1 root root 640 Feb 25 16:49 students.cfg -rw-r----- 1 root root 16384 Feb 25 16:49 students.exp -rw-r----- 1 root root 1208 Feb 25 16:23 students.frm -rw-r----- 1 root root 98304 Feb 25 16:23 students.ibd 恢復表之前,先創建表結構; MariaDB [(none)]> use hellodb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [hellodb]> CREATE TABLE `students` ( -> `StuID` int(10) unsigned NOT NULL AUTO_INCREMENT, -> `Name` varchar(50) NOT NULL, -> `Age` tinyint(3) unsigned NOT NULL, -> `Gender` enum('F','M') NOT NULL, -> `ClassID` tinyint(3) unsigned DEFAULT NULL, -> `TeacherID` int(10) unsigned DEFAULT NULL, -> PRIMARY KEY (`StuID`) -> ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.01 sec) MariaDB [hellodb]> select * from students; Empty set (0.00 sec) MariaDB [hellodb]> desc students; +-----------+---------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+---------------------+------+-----+---------+----------------+ | StuID | int(10) unsigned | NO | PRI | NULL | auto_increment | | Name | varchar(50) | NO | | NULL | | | Age | tinyint(3) unsigned | NO | | NULL | | | Gender | enum('F','M') | NO | | NULL | | | ClassID | tinyint(3) unsigned | YES | | NULL | | | TeacherID | int(10) unsigned | YES | | NULL | | +-----------+---------------------+------+-----+---------+----------------+ 6 rows in set (0.00 sec) 此時雖然有表結構和數據文件,但是沒有數據; [root@centos7x ~]$ll /var/lib/mysql/hellodb/ -h total 704K -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 classes.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 classes.ibd -rw-rw---- 1 mysql mysql 976 Feb 25 16:18 coc.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 coc.ibd -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 courses.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 courses.ibd -rw-rw---- 1 mysql mysql 61 Feb 25 16:18 db.opt -rw-rw---- 1 mysql mysql 1001 Feb 25 16:18 scores.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 scores.ibd -rw-rw---- 1 mysql mysql 1.2K Feb 25 16:53 students.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:53 students.ibd -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 teachers.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 teachers.ibd -rw-rw---- 1 mysql mysql 973 Feb 25 16:18 toc.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 toc.ibd 于是要刪除這個表空間文件,即數據文件;但是不要使用rm刪除,而是使用命令刪除; MariaDB [hellodb]> alter table students discard tablespace; Query OK, 0 rows affected (0.00 sec) [root@centos7x ~]$ll /var/lib/mysql/hellodb/ -h total 608K -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 classes.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 classes.ibd -rw-rw---- 1 mysql mysql 976 Feb 25 16:18 coc.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 coc.ibd -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 courses.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 courses.ibd -rw-rw---- 1 mysql mysql 61 Feb 25 16:18 db.opt -rw-rw---- 1 mysql mysql 1001 Feb 25 16:18 scores.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 scores.ibd -rw-rw---- 1 mysql mysql 1.2K Feb 25 16:53 students.frm -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 teachers.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 teachers.ibd -rw-rw---- 1 mysql mysql 973 Feb 25 16:18 toc.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 toc.ibd [root@centos7x ~]$cp /backups/2018-02-25_16-23-08/hellodb/students.{cfg,ibd,exp} /var/lib/mysql/hellodb/ [root@centos7x ~]$ll /var/lib/mysql/hellodb/ -h total 724K -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 classes.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 classes.ibd -rw-rw---- 1 mysql mysql 976 Feb 25 16:18 coc.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 coc.ibd -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 courses.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 courses.ibd -rw-rw---- 1 mysql mysql 61 Feb 25 16:18 db.opt -rw-rw---- 1 mysql mysql 1001 Feb 25 16:18 scores.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 scores.ibd -rw-r--r-- 1 root root 640 Feb 25 16:59 students.cfg -rw-r----- 1 root root 16K Feb 25 16:59 students.exp -rw-rw---- 1 mysql mysql 1.2K Feb 25 16:53 students.frm -rw-r----- 1 root root 96K Feb 25 16:59 students.ibd -rw-rw---- 1 mysql mysql 1.3K Feb 25 16:18 teachers.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 teachers.ibd -rw-rw---- 1 mysql mysql 973 Feb 25 16:18 toc.frm -rw-rw---- 1 mysql mysql 96K Feb 25 16:18 toc.ibd [root@centos7x ~]$chown -R mysql.mysql /var/lib/mysql/hellodb/ 接著是導入表空間,盡管文件放在數據目錄下了,但是表空間還沒有關聯; MariaDB [hellodb]> alter table students import tablespace; Query OK, 0 rows affected (0.02 sec)
數據和表結構驗證操作:
驗證; MariaDB [hellodb]> select * from students; +-------+---------------+-----+--------+---------+-----------+ | StuID | Name | Age | Gender | ClassID | TeacherID | +-------+---------------+-----+--------+---------+-----------+ | 1 | Shi Zhongyu | 22 | M | 2 | 3 | | 2 | Shi Potian | 22 | M | 1 | 7 | | 3 | Xie Yanke | 53 | M | 2 | 16 | | 4 | Ding Dian | 32 | M | 4 | 4 |
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。