mysql无备份恢复创建独立表空间
本篇内容主要讲解"mysql无备份恢复创建独立表空间",感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习"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存储过程插入数据
点击(此处)折叠或打开
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`);
根据table_id得到index_id,index_id对应恢复数据文件
点击(此处)折叠或打开
[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)
到此,相信大家对"mysql无备份恢复创建独立表空间"有了更深的了解,不妨来实际操作一番吧!这里是网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!