mysql無備份恢復-獨立表空間
建立恢復庫
點選(此處)摺疊或開啟
-
mysql> create database helpdb default charset utf8;
- Query OK, 1 row affected (0.01 sec)
點選(此處)摺疊或開啟
-
mysql>
-
CREATE TABLE `newaccount` (
-
`id` int(11) NOT NULL AUTO_INCREMENT,
-
`username` varchar(50) DEFAULT NULL,
-
`userpwd` varchar(50) DEFAULT NULL,
-
`createtime` datetime DEFAULT NULL,
-
PRIMARY KEY (`id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
建立對應函式
點選(此處)摺疊或開啟
-
DELIMITER $$
-
USE `helpdb`$$
-
DROP FUNCTION IF EXISTS `rand_string`$$
-
CREATE DEFINER=`root`@`%` FUNCTION `rand_string`(n INT) RETURNS VARCHAR(255) CHARSET latin1
-
BEGIN
-
DECLARE chars_str VARCHAR(100) DEFAULT 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
-
DECLARE return_str VARCHAR(255) DEFAULT '';
-
DECLARE i INT DEFAULT 0;
-
WHILE i < n DO
-
SET return_str = CONCAT(return_str,SUBSTRING(chars_str , FLOOR(1 + RAND()*62 ),1));
-
SET i = i +1;
-
END WHILE;
-
RETURN return_str;
-
END$$
- DELIMITER ;
點選(此處)摺疊或開啟
-
DELIMITER $$
-
USE `helpdb` $$
-
DROP PROCEDURE IF EXISTS `p_repeat` $$
-
CREATE DEFINER = `root` @`%` PROCEDURE `p_repeat` ()
-
BEGIN
-
DECLARE v INT ;
-
SET v = 0 ;
-
REPEAT
-
INSERT INTO newaccount
-
VALUES
-
(
-
NULL,
-
rand_string (5),
-
rand_string (15),
-
NOW()
-
) ;
-
SET v = v + 1 ;
-
UNTIL v >= 1000
-
END REPEAT ;
-
END $$
- DELIMITER ;
點選(此處)摺疊或開啟
-
mysql> CALL p_repeat;
-
Query OK, 1 row affected (1.62 sec)
-
mysql> select count(*) from newaccount;
-
+----------+
-
| count(*) |
-
+----------+
-
| 1000 |
- +----------+
手動插入資料
點選(此處)摺疊或開啟
-
mysql> insert into newaccount values(null,'netdata','pwdnetdata',now());
-
Query OK, 1 row affected (0.00 sec)
-
mysql> select * from newaccount where id=1001;
-
+------+----------+------------+---------------------+
-
| id | username | userpwd | createtime |
-
+------+----------+------------+---------------------+
-
| 1001 | netdata | pwdnetdata | 2017-11-12 01:37:52 |
-
+------+----------+------------+---------------------+
- 1 row in set (0.00 sec)
刪除表
點選(此處)摺疊或開啟
-
mysql> drop table newaccount;
- Query OK, 0 rows affected (0.01 sec)
關閉庫
點選(此處)摺疊或開啟
- [root@mysqltest-213-2 undrop-for-innodb-master]# /etc/init.d/mysql stop
- Shutting down MySQL.. SUCCESS!
- [root@mysqltest-213-2 undrop-for-innodb-master]#
- 1 row in set (0.00 sec)
- [root@mysqltest-213-2 undrop-for-innodb-master]# ./stream_parser -f /var/lib/mysql/ibdata1
- Opening file: /var/lib/mysql/ibdata1
- File information:
- ID of device containing file: 64768
- inode number: 393238
- protection: 100660 (regular file)
- number of hard links: 1
- user ID of owner: 498
- group ID of owner: 500
- device ID (if special file): 0
- blocksize for filesystem I/O: 4096
- number of blocks allocated: 155648
- time of last access: 1510422066 Sun Nov 12 01:41:06 2017
- time of last modification: 1510422066 Sun Nov 12 01:41:06 2017
- time of last status change: 1510422066 Sun Nov 12 01:41:06 2017
- total size, in bytes: 79691776 (76.000 MiB)
- Size to process: 79691776 (76.000 MiB)
- Worker(0): 21.03% done. 2017-11-12 01:41:49 ETA(in 00:00:07). Processing speed: 7.984 MiB/sec
All workers finished in 1 sec
解析資料檔案,得到table_id=228
點選(此處)摺疊或開啟
- [root@mysqltest-213-2 undrop-for-innodb-master]# ./c_parser -4Df pages-ibdata1/FIL_PAGE_INDEX/0000000000000001.page -t dictionary/SYS_TABLES.sql |grep newaccount
- 00000007A50E 030000024B0D54 SYS_TABLES "helpdb/newaccount" 71 4 1 0 80 "" 57
- 00000007A50E 030000024B0D54 SYS_TABLES "helpdb/newaccount" 71 4 1 0 80 "" 57
- SET FOREIGN_KEY_CHECKS=0;
- LOAD DATA LOCAL INFILE '/usr/local/tools/undrop-for-innodb-master/dumps/default/SYS_TABLES' REPLACE INTO TABLE `SYS_TABLES` FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES STARTING BY 'SYS_TABLES\t' (`NAME`, `ID`, `N_COLS`, `TYPE`, `MIX_ID`, `MIX_LEN`, `CLUSTER_NAME`, `SPACE`);
點選(此處)摺疊或開啟
- [root@mysqltest-213-2 undrop-for-innodb-master]# ./c_parser -4Df pages-ibdata1/FIL_PAGE_INDEX/0000000000000003.page -t dictionary/SYS_INDEXES.sql |grep 71
- SET FOREIGN_KEY_CHECKS=0;
- LOAD DATA LOCAL INFILE '/usr/local/tools/undrop-for-innodb-master/dumps/default/SYS_INDEXES' REPLACE INTO TABLE `SYS_INDEXES` FIELDS TERMINATED BY '\t' OPTIONALLY ENCLOSED BY '"' LINES STARTING BY 'SYS_INDEXES\t' (`TABLE_ID`, `ID`, `NAME`, `N_FIELDS`, `TYPE`, `SPACE`, `PAGE_NO`);
- 00000007A50E 030000024B0BFF SYS_INDEXES 71 74 "PRIMARY" 1 3 57 4294967295
- 00000007A50E 030000024B0BFF SYS_INDEXES 71 74 "PRIMARY" 1 3 57 4294967295
點選(此處)摺疊或開啟
- [root@mysqltest-213-2 undrop-for-innodb-master]# ./stream_parser -f /dev/mapper/vg_mysqltest2132-lv_root -t 18G
- Opening file: /dev/mapper/vg_mysqltest2132-lv_root
- File information:
- ID of device containing file: 5
- inode number: 6976
- protection: 60660 (block device)
- number of hard links: 1
- user ID of owner: 0
- group ID of owner: 6
- device ID (if special file): 64768
- blocksize for filesystem I/O: 4096
- number of blocks allocated: 0
- time of last access: 1510407590 Sat Nov 11 21:39:50 2017
- time of last modification: 1510407590 Sat Nov 11 21:39:50 2017
- time of last status change: 1510407590 Sat Nov 11 21:39:50 2017
- total size, in bytes: 0 (0.000 exp(+0))
- Size to process: 19327352832 (18.000 GiB)
- Worker(0): 1.08% done. 2017-11-12 01:46:39 ETA(in 00:03:10). Processing speed: 95.945 MiB/sec
- Worker(0): 2.12% done. 2017-11-12 01:48:14 ETA(in 00:04:42). Processing speed: 63.880 MiB/sec
- Worker(0): 3.16% done. 2017-11-12 01:54:30 ETA(in 00:10:51). Processing speed: 27.377 MiB/sec
- Worker(0): 4.20% done. 2017-11-12 01:46:45 ETA(in 00:03:04). Processing speed: 95.844 MiB/sec
- Worker(0): 5.24% done. 2017-11-12 01:46:45 ETA(in 00:03:02). Processing speed: 95.820 MiB/sec
- Worker(0): 6.28% done. 2017-11-12 01:48:16 ETA(in 00:04:30). Processing speed: 63.880 MiB/sec
- Worker(0): 7.32% done. 2017-11-12 01:48:16 ETA(in 00:04:27). Processing speed: 63.896 MiB/sec
- Worker(0): 8.36% done. 2017-11-12 01:46:47 ETA(in 00:02:56). Processing speed: 95.828 MiB/sec
- Worker(0): 9.40% done. 2017-11-12 01:46:47 ETA(in 00:02:54). Processing speed: 95.906 MiB/sec
- Worker(0): 10.44% done. 2017-11-12 01:46:47 ETA(in 00:02:52). Processing speed: 95.891 MiB/sec
- Worker(0): 11.49% done. 2017-11-12 01:45:20 ETA(in 00:01:24). Processing speed: 192.000 MiB/sec
- Worker(0): 12.53% done. 2017-11-12 01:46:46 ETA(in 00:02:48). Processing speed: 95.883 MiB/sec
- Worker(0): 13.57% done. 2017-11-12 01:45:22 ETA(in 00:01:23). Processing speed: 191.938 MiB/sec
- Worker(0): 15.09% done. 2017-11-12 01:44:55 ETA(in 00:00:55). Processing speed: 280.000 MiB/sec
- Worker(0): 17.13% done. 2017-11-12 01:44:41 ETA(in 00:00:40). Processing speed: 376.000 MiB/sec
- Worker(0): 19.04% done. 2017-11-12 01:44:44 ETA(in 00:00:42). Processing speed: 352.000 MiB/sec
- Worker(0): 20.99% done. 2017-11-12 01:44:43 ETA(in 00:00:40). Processing speed: 360.000 MiB/sec
- Worker(0): 22.90% done. 2017-11-12 01:44:44 ETA(in 00:00:40). Processing speed: 352.000 MiB/sec
- Worker(0): 24.81% done. 2017-11-12 01:44:44 ETA(in 00:00:39). Processing speed: 352.000 MiB/sec
- Worker(0): 26.46% done. 2017-11-12 01:44:50 ETA(in 00:00:44). Processing speed: 304.000 MiB/sec
- Worker(0): 28.54% done. 2017-11-12 01:44:41 ETA(in 00:00:34). Processing speed: 384.000 MiB/sec
- Worker(0): 30.54% done. 2017-11-12 01:44:42 ETA(in 00:00:34). Processing speed: 368.000 MiB/sec
- Worker(0): 32.45% done. 2017-11-12 01:44:44 ETA(in 00:00:35). Processing speed: 352.000 MiB/sec
- Worker(0): 34.05% done. 2017-11-12 01:44:51 ETA(in 00:00:41). Processing speed: 296.000 MiB/sec
- Worker(0): 35.49% done. 2017-11-12 01:44:56 ETA(in 00:00:45). Processing speed: 263.930 MiB/sec
- Worker(0): 37.44% done. 2017-11-12 01:44:44 ETA(in 00:00:32). Processing speed: 360.000 MiB/sec
- Worker(0): 39.39% done. 2017-11-12 01:44:44 ETA(in 00:00:31). Processing speed: 360.000 MiB/sec
- Worker(0): 40.95% done. 2017-11-12 01:44:51 ETA(in 00:00:37). Processing speed: 288.000 MiB/sec
- Worker(0): 42.95% done. 2017-11-12 01:44:43 ETA(in 00:00:28). Processing speed: 368.000 MiB/sec
- Worker(0): 44.86% done. 2017-11-12 01:44:44 ETA(in 00:00:28). Processing speed: 352.000 MiB/sec
- Worker(0): 45.90% done. 2017-11-12 01:45:09 ETA(in 00:00:52). Processing speed: 191.750 MiB/sec
- Worker(0): 46.94% done. 2017-11-12 01:45:08 ETA(in 00:00:50). Processing speed: 192.000 MiB/sec
- Worker(0): 48.90% done. 2017-11-12 01:44:45 ETA(in 00:00:26). Processing speed: 360.000 MiB/sec
- Worker(0): 50.89% done. 2017-11-12 01:44:44 ETA(in 00:00:24). Processing speed: 368.000 MiB/sec
- Worker(0): 52.80% done. 2017-11-12 01:44:45 ETA(in 00:00:24). Processing speed: 352.000 MiB/sec
- Worker(0): 54.71% done. 2017-11-12 01:44:45 ETA(in 00:00:23). Processing speed: 352.000 MiB/sec
- Worker(0): 56.27% done. 2017-11-12 01:44:50 ETA(in 00:00:27). Processing speed: 288.000 MiB/sec
- Worker(0): 57.66% done. 2017-11-12 01:44:54 ETA(in 00:00:30). Processing speed: 255.937 MiB/sec
- Worker(0): 59.70% done. 2017-11-12 01:44:44 ETA(in 00:00:19). Processing speed: 376.000 MiB/sec
- Worker(0): 61.66% done. 2017-11-12 01:44:45 ETA(in 00:00:19). Processing speed: 360.000 MiB/sec
- Worker(0): 63.61% done. 2017-11-12 01:44:45 ETA(in 00:00:18). Processing speed: 360.000 MiB/sec
- Worker(0): 65.69% done. 2017-11-12 01:44:44 ETA(in 00:00:16). Processing speed: 384.000 MiB/sec
- Worker(0): 67.34% done. 2017-11-12 01:44:48 ETA(in 00:00:19). Processing speed: 304.000 MiB/sec
- Worker(0): 68.38% done. 2017-11-12 01:45:00 ETA(in 00:00:30). Processing speed: 191.922 MiB/sec
- Worker(0): 69.95% done. 2017-11-12 01:44:50 ETA(in 00:00:19). Processing speed: 288.000 MiB/sec
- Worker(0): 71.94% done. 2017-11-12 01:44:46 ETA(in 00:00:14). Processing speed: 368.000 MiB/sec
- Worker(0): 73.98% done. 2017-11-12 01:44:45 ETA(in 00:00:12). Processing speed: 376.000 MiB/sec
- Worker(0): 76.02% done. 2017-11-12 01:44:45 ETA(in 00:00:11). Processing speed: 376.000 MiB/sec
- Worker(0): 77.76% done. 2017-11-12 01:44:47 ETA(in 00:00:12). Processing speed: 320.000 MiB/sec
- Worker(0): 78.80% done. 2017-11-12 01:44:56 ETA(in 00:00:20). Processing speed: 191.891 MiB/sec
- Worker(0): 79.84% done. 2017-11-12 01:45:16 ETA(in 00:00:38). Processing speed: 95.813 MiB/sec
- Worker(0): 80.88% done. 2017-11-12 01:44:57 ETA(in 00:00:18). Processing speed: 191.891 MiB/sec
- Worker(0): 81.92% done. 2017-11-12 01:44:57 ETA(in 00:00:17). Processing speed: 192.000 MiB/sec
- Worker(0): 83.31% done. 2017-11-12 01:44:53 ETA(in 00:00:12). Processing speed: 256.000 MiB/sec
- Worker(0): 85.35% done. 2017-11-12 01:44:49 ETA(in 00:00:07). Processing speed: 376.000 MiB/sec
- Worker(0): 86.91% done. 2017-11-12 01:44:51 ETA(in 00:00:08). Processing speed: 288.000 MiB/sec
- Worker(0): 88.69% done. 2017-11-12 01:44:50 ETA(in 00:00:06). Processing speed: 328.000 MiB/sec
- Worker(0): 89.73% done. 2017-11-12 01:44:54 ETA(in 00:00:09). Processing speed: 191.939 MiB/sec
- Worker(0): 90.77% done. 2017-11-12 01:44:54 ETA(in 00:00:08). Processing speed: 191.883 MiB/sec
- Worker(0): 92.51% done. 2017-11-12 01:44:51 ETA(in 00:00:04). Processing speed: 320.000 MiB/sec
- Worker(0): 93.55% done. 2017-11-12 01:44:54 ETA(in 00:00:06). Processing speed: 192.000 MiB/sec
- Worker(0): 95.29% done. 2017-11-12 01:44:51 ETA(in 00:00:02). Processing speed: 320.000 MiB/sec
- Worker(0): 97.11% done. 2017-11-12 01:44:51 ETA(in 00:00:01). Processing speed: 336.000 MiB/sec
- All workers finished in 83 sec
檢視對應資料頁檔案
點選(此處)摺疊或開啟
- [root@mysqltest-213-2 undrop-for-innodb-master]# ls pages-vg_mysqltest2132-lv_root/FIL_PAGE_INDEX/0000000000000074.page
- pages-vg_mysqltest2132-lv_root/FIL_PAGE_INDEX/0000000000000074.page
恢復表結構
點選(此處)摺疊或開啟
-
[root@mysqltest-213-2 undrop-for-innodb-master]# cat newaccount.sql
-
CREATE TABLE `newaccount` (
-
`id` int(11) NOT NULL AUTO_INCREMENT,
-
`username` varchar(50) DEFAULT NULL,
-
`userpwd` varchar(50) DEFAULT NULL,
-
`createtime` datetime DEFAULT NULL,
-
PRIMARY KEY (`id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
點選(此處)摺疊或開啟
- [root@mysqltest-213-2 undrop-for-innodb-master]# ./c_parser -6f pages-ibdata1/FIL_PAGE_INDEX/0000000000000074.page -t newaccount.sql | head -5
- -- Page id: 5, Format: COMPACT, Records list: Valid, Expected records: (301 301)
- 00000007A1B5 AC0000015F0110 newaccount 151 "0GdUH" "DTo9njhkAO9adoc" "2017-11-12 01:36:10.0"
- 00000007A1B6 AD000001600110 newaccount 152 "CoT8Q" "DtjZQ4Iaz9UVKOD" "2017-11-12 01:36:10.0"
- 00000007A1B7 AE000001610110 newaccount 153 "CZWzT" "z1f1aEyGzEnLzo7" "2017-11-12 01:36:10.0"
- 00000007A1B8 AF000001620110 newaccount 154 "eEpWh" "p50DYNW9J41Hkkv" "2017-11-12 01:36:10.0"
恢復資料
抽取資料轉換成檔案
點選(此處)摺疊或開啟
- [root@mysqltest-213-2 undrop-for-innodb-master]# ./c_parser -6f pages-vg_mysqltest2132-lv_root/FIL_PAGE_INDEX/0000000000000074.page -t newaccount.sql -o dumps/default/newaccount.dump -l dumps/default/newaccount.sql
- [root@mysqltest-213-2 undrop-for-innodb-master]# ls -alh dumps/default/newaccount.*
- -rw-r--r--. 1 root root 92K Nov 12 01:48 dumps/default/newaccount.dump
- -rw-r--r--. 1 root root 244 Nov 12 01:48 dumps/default/newaccount.sql
點選(此處)摺疊或開啟
-
mysql> source dumps/default/newaccount.sql;
-
Query OK, 0 rows affected (0.00 sec)
-
Query OK, 6002 rows affected (0.06 sec)
-
Records: 6002 Deleted: 0 Skipped: 0 Warnings: 0
-
mysql> select count(*) from newaccount;
-
+----------+
-
| count(*) |
-
+----------+
-
| 1001 |
-
+----------+
-
1 row in set (0.00 sec)
-
mysql> checksum table newaccount;
-
+-------------------+------------+
-
| Table | Checksum |
-
+-------------------+------------+
-
| helpdb.newaccount | 2512700176 |
-
+-------------------+------------+
- 1 row in set (0.03 sec)
參閱文件
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24486203/viewspace-2147148/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SYSTEM 表空間管理及備份恢復
- 【PG備份恢復】pg_basebackup 多表空間備份恢復測試
- MySQL UNDO表空間獨立和截斷MySql
- MySQL 中的共享表空間與獨立表空間如何選擇MySql
- MySQL 遷移表空間,備份單表MySql
- Mysql備份恢復MySql
- 【MySQL】MySQL備份和恢復MySql
- MySQL備份與恢復——基於Xtrabackup物理備份恢復MySql
- MySQL 備份與恢復MySql
- Mysql備份與恢復(1)---物理備份MySql
- Oracle RMAN 表空間恢復Oracle
- MySQL備份與恢復——基於MyDumper/MyLoader 邏輯備份恢復MySql
- PostgreSQL從小白到高手教程 - 第41講:postgres表空間備份與恢復SQL
- MySQL 非常規恢復與物理備份恢復MySql
- Mysql備份與恢復(2)---邏輯備份MySql
- MySQL備份與恢復——基於OUTFILE /LOAD DATA 邏輯備份恢復MySql
- 表空間TSPITR恢復-實驗
- 【Oracle 恢復表空間】 實驗Oracle
- 《入門MySQL—備份與恢復》MySql
- MySQL備份與恢復——實操MySql
- 入門MySQL——備份與恢復MySql
- docker 中 MySQL 備份及恢復DockerMySql
- MySQL備份與恢復操作解析MySql
- Mysql資料備份與恢復MySql
- innobackupex 部分表備份和恢復
- 為Zabbix MySQL設定獨立表空間innodb_file_per_tableMySql
- RAC備份恢復之Voting備份與恢復
- Mysql的幾種備份與恢復MySql
- 【MySQL】Xtrabackup備份及恢復指令碼MySql指令碼
- Mysql資料庫備份及恢復MySql資料庫
- MySQL8.4備份恢復快速命令MySql
- MySQL入門--備份與恢復(三)MySql
- MySQL入門--備份與恢復(一)MySql
- MySQL入門--備份與恢復(二)MySql
- MySQL 日誌管理、備份與恢復MySql
- MySQL日誌管理,備份和恢復MySql
- MySQL備份和恢復方法彙總MySql
- 備份與恢復:polardb資料庫備份與恢復資料庫
- 解密MySQL備份恢復的4種方法解密MySql