<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>惜分飞 &#187; 无主键</title>
	<atom:link href="https://www.xifenfei.com/tag/%e6%97%a0%e4%b8%bb%e9%94%ae/feed" rel="self" type="application/rss+xml" />
	<link>https://www.xifenfei.com</link>
	<description>提供7*24专业数据库(Oracle,SQL Server,MySQL,PostgreSQL等)恢复和技术支持@Tel:17813235971</description>
	<lastBuildDate>Sat, 07 Nov 2026 15:45:44 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>[MySQL异常恢复]无主键情况下innodb数据恢复</title>
		<link>https://www.xifenfei.com/2015/08/mysql%e5%bc%82%e5%b8%b8%e6%81%a2%e5%a4%8d%e6%97%a0%e4%b8%bb%e9%94%ae%e6%83%85%e5%86%b5%e4%b8%8binnodb%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d.html</link>
		<comments>https://www.xifenfei.com/2015/08/mysql%e5%bc%82%e5%b8%b8%e6%81%a2%e5%a4%8d%e6%97%a0%e4%b8%bb%e9%94%ae%e6%83%85%e5%86%b5%e4%b8%8binnodb%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d.html#comments</comments>
		<pubDate>Sat, 29 Aug 2015 04:35:44 +0000</pubDate>
		<dc:creator><![CDATA[惜分飞]]></dc:creator>
				<category><![CDATA[MySQL恢复]]></category>
		<category><![CDATA[innodb恢复]]></category>
		<category><![CDATA[无主键]]></category>

		<guid isPermaLink="false">https://www.xifenfei.com/?p=6078</guid>
		<description><![CDATA[联系：手机/微信(+86 17813235971) QQ(107644445)  &#8230; <a href="https://www.xifenfei.com/2015/08/mysql%e5%bc%82%e5%b8%b8%e6%81%a2%e5%a4%8d%e6%97%a0%e4%b8%bb%e9%94%ae%e6%83%85%e5%86%b5%e4%b8%8binnodb%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d.html">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<div id="xifenfeicopyright">
<p>联系：<a href="https://www.xifenfei.com/about_xifenfei" target="_blank">手机/微信(+86 17813235971)   QQ(107644445)</a><a target="_blank" href="http://wpa.qq.com/msgrd?v=3&#038;uin=107644445&#038;site=qq&#038;menu=yes"><img src="https://www.xifenfei.com/wp-content/themes/img/site_qq.jpg" alt="QQ咨询惜分飞" title="QQ咨询惜分飞"/></a></p>
<p>标题：<a href="https://www.xifenfei.com/2015/08/mysql%e5%bc%82%e5%b8%b8%e6%81%a2%e5%a4%8d%e6%97%a0%e4%b8%bb%e9%94%ae%e6%83%85%e5%86%b5%e4%b8%8binnodb%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d.html" target="_blank">[MySQL异常恢复]无主键情况下innodb数据恢复</a></p>
<p>作者：<a href="https://www.xifenfei.com" target="_blank">惜分飞</a>©版权所有[未经本人同意,不得以任何形式转载,否则有进一步追究法律责任的权利.]</p>
</div>
<p>在mysql的innodb引擎的数据库异常恢复中,一般都要求有主键或者唯一index,其实这个不是必须的,当没有index信息之时,可以在整个表级别的index_id进行恢复<br />
<strong>创建模拟表&#8212;无主键</strong></p>
<pre class="brush: sql; title: ; notranslate">
mysql&gt;  CREATE TABLE `t1` (
    -&gt;   `messageId` varchar(30) character set utf8 NOT NULL,
    -&gt;   `tokenId` varchar(20) character set utf8 NOT NULL,
    -&gt;   `mobile` varchar(14) character set utf8 default NULL,
    -&gt;   `msgFormat` int(1) NOT NULL,
    -&gt;   `msgContent` varchar(1000) character set utf8 default NULL,
    -&gt;   `scheduleDate` timestamp NOT NULL default '0000-00-00 00:00:00',
    -&gt;   `deliverState` int(1) default NULL,
    -&gt;   `deliverdTime` timestamp NOT NULL default '0000-00-00 00:00:00'
    -&gt; ) ENGINE=INnodb DEFAULT CHARSET=utf8;
Query OK, 0 rows affected (0.00 sec)

mysql&gt; insert into t1 select * from sms_service.sms_send_record;
Query OK, 11 rows affected (0.00 sec)
Records: 11  Duplicates: 0  Warnings: 0
…………
mysql&gt; insert into t1 select * from t1;
Query OK, 81664 rows affected (2.86 sec)
Records: 81664  Duplicates: 0  Warnings: 0

mysql&gt; insert into t1 select * from t1;
Query OK, 163328 rows affected (2.74 sec)
Records: 163328  Duplicates: 0  Warnings: 0

mysql&gt; select count(*) from t1;
+----------+
| count(*) |
+----------+
|   326656 | 
+----------+
1 row in set (0.15 sec)
</pre>
<p><strong>解析innodb文件</strong></p>
<pre class="brush: bash; title: ; notranslate">
[root@web103 mysql_recovery]# rm -rf pages-ibdata1/
[root@web103 mysql_recovery]# ./stream_parser -f /var/lib/mysql/ibdata1 
Opening file: /var/lib/mysql/ibdata1
File information:

ID of device containing file:         2049
inode number:                      1344553
protection:                         100660 (regular file)
number of hard links:                    1
user ID of owner:                       27
group ID of owner:                      27
device ID (if special file):             0
blocksize for filesystem I/O:         4096
number of blocks allocated:         463312
time of last access:            1440819443 Sat Aug 29 11:37:23 2015
time of last modification:      1440819463 Sat Aug 29 11:37:43 2015
time of last status change:     1440819463 Sat Aug 29 11:37:43 2015
total size, in bytes:            236978176 (226.000 MiB)

Size to process:                 236978176 (226.000 MiB)
Opening file: /var/lib/mysql/ibdata1
File information:

ID of device containing file:         2049
inode number:                      1344553
protection:                         100660 (regular file)
number of hard links:                    1
user ID of owner:                       27
group ID of owner:                      27
device ID (if special file):             0
blocksize for filesystem I/O:         4096
number of blocks allocated:         463312
Opening file: /var/lib/mysql/ibdata1
File information:

time of last access:            1440819443 Sat Aug 29 11:37:23 2015
time of last modification:      1440819463 Sat Aug 29 11:37:43 2015
ID of device containing file:         2049
inode number:                      1344553
protection:                         100660 time of last status change:     1440819463 Sat Aug 29 11:37:43 2015
total size, in bytes:            236978176 (226.000 MiB)

Size to process:                 236978176 (226.000 MiB)
Opening file: /var/lib/mysql/ibdata1
File information:

ID of device containing file:         2049
inode number:                      1344553
protection:                         100660 (regular file)
number of hard links:                    1
user ID of owner:                       27
group ID of owner:                      27
device ID (if special file):             0
blocksize for filesystem I/O:         4096
number of blocks allocated:         463312
time of last access:            1440819443 Sat Aug 29 11:37:23 2015
time of last modification:      1440819463 Sat Aug 29 11:37:43 2015
time of last status change:     1440819463 Sat Aug 29 11:37:43 2015
total size, in bytes:            236978176 (226.000 MiB)

Size to process:                 236978176 (226.000 MiB)
(regular file)
number of hard links:                    1
user ID of owner:                       27
group ID of owner:                      27
device ID (if special file):             0
blocksize for filesystem I/O:         4096
number of blocks allocated:         463312
time of last access:            1440819443 Sat Aug 29 11:37:23 2015
time of last modification:      1440819463 Sat Aug 29 11:37:43 2015
time of last status change:     1440819463 Sat Aug 29 11:37:43 2015
total size, in bytes:            236978176 (226.000 MiB)

Size to process:                 236978176 (226.000 MiB)
Opening file: /var/lib/mysql/ibdata1
File information:

ID of device containing file:         2049
inode number:                      1344553
protection:                         100660 (regular file)
number of hard links:                    1
user ID of owner:                       27
group ID of owner:                      27
device ID (if special file):             0
blocksize for filesystem I/O:         4096
number of blocks allocated:         463312
time of last access:            1440819443 Sat Aug 29 11:37:23 2015
time of last modification:      1440819463 Sat Aug 29 11:37:43 2015
time of last status change:     1440819463 Sat Aug 29 11:37:43 2015
total size, in bytes:            236978176 (226.000 MiB)

Size to process:                 236978176 (226.000 MiB)
Opening file: /var/lib/mysql/ibdata1
File information:

ID of device containing file:         2049
inode number:                      1344553
protection:                         100660 (regular file)
number of hard links:                    1
user ID of owner:                       27
group ID of owner:                      27
device ID (if special file):             0
blocksize for filesystem I/O:         4096
number of blocks allocated:         463312
time of last access:            1440819443 Sat Aug 29 11:37:23 2015
time of last modification:      1440819463 Sat Aug 29 11:37:43 2015
time of last status change:     1440819463 Sat Aug 29 11:37:43 2015
Opening file: /var/lib/mysql/ibdata1
File information:

ID of device containing file:         2049
inode number:                      1344553
protection:                         100660 (regular file)
number of hard links:                    1
user ID of owner:                       27
group ID of owner:                      27
device ID (if special file):             0
blocksize for filesystem I/O:         4096
number of blocks allocated:         463312
total size, in bytes:            236978176 (226.000 MiB)

Size to process:                 236978176 (226.000 MiB)
time of last access:            1440819443 Sat Aug 29 11:37:23 2015
time of last modification:      1440819463 Sat Aug 29 11:37:43 2015
time of last status change:     1440819463 Sat Aug 29 11:37:43 2015
total size, in bytes:            236978176 (226.000 MiB)

Size to process:                 236978176 (226.000 MiB)
Opening file: /var/lib/mysql/ibdata1
File information:

ID of device containing file:         2049
inode number:                      1344553
protection:                         100660 (regular file)
number of hard links:                    1
user ID of owner:                       27
group ID of owner:                      27
device ID (if special file):             0
blocksize for filesystem I/O:         4096
number of blocks allocated:         463312
time of last access:            1440819465 Sat Aug 29 11:37:45 2015
time of last modification:      1440819463 Sat Aug 29 11:37:43 2015
time of last status change:     1440819463 Sat Aug 29 11:37:43 2015
total size, in bytes:            236978176 (226.000 MiB)

Size to process:                 236978176 (226.000 MiB)
All workers finished in 0 sec
</pre>
<p><strong>恢复数据字典</strong></p>
<pre class="brush: bash; title: ; notranslate">
[root@web103 mysql_recovery]# ./recover_dictionary.sh 
Generating dictionary tables dumps... OK
Creating test database ... OK
Creating dictionary tables in database test:
SYS_TABLES ... OK
SYS_COLUMNS ... OK
SYS_INDEXES ... OK
SYS_FIELDS ... OK
All OK
Loading dictionary tables data:
SYS_TABLES ... 48 recs OK
SYS_COLUMNS ... 397 recs OK
SYS_INDEXES ... 67 recs OK
SYS_FIELDS ... 89 recs OK
All OK
</pre>
<p><strong>分析数据字典,找出来index_id</strong><br />
这里需要注意对于没有主键的表恢复,我们对应的类型是GEN_CLUST_INDEX</p>
<pre class="brush: sql; title: ; notranslate">
mysql&gt; select * from SYS_TABLES where name='test/t1';
+----------------------------------------+-----+-------------+------+--------+---------+--------------+-------+
| NAME                                   | ID  | N_COLS      | TYPE | MIX_ID | MIX_LEN | CLUSTER_NAME | SPACE |
+----------------------------------------+-----+-------------+------+--------+---------+--------------+-------+
| test/t1                                | 100 |           8 |    1 |      0 |       0 |              |     0 | 
+----------------------------------------+-----+-------------+------+--------+---------+--------------+-------+
40 rows in set (0.00 sec)

mysql&gt; SELECT * FROM SYS_INDEXES where table_id=100;
+----------+-----+------------------------------+----------+------+-------+------------+
| TABLE_ID | ID  | NAME                         | N_FIELDS | TYPE | SPACE | PAGE_NO    |
+----------+-----+------------------------------+----------+------+-------+------------+
|      100 | 119 | GEN_CLUST_INDEX              |        0 |    1 |     0 |       2951 | 
+----------+-----+------------------------------+----------+------+-------+------------+
67 rows in set (0.00 sec)
</pre>
<p><strong>恢复数据</strong></p>
<pre class="brush: bash; title: ; notranslate">
root@web103 mysql_recovery]# ./c_parser -5f pages-ibdata1/FIL_PAGE_INDEX/0000000000000119.page  -t dictionary/t1.sql &gt;/tmp/2.txt 2&gt;2.sql
[root@web103 mysql_recovery]# more /tmp/2.txt
-- Page id: 10848, Format: COMPACT, Records list: Valid, Expected records: (73 73)
00000002141B    0000009924F2    80000027133548  t1      &quot;82334502212106951&quot;     &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为916515如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;1970-01-01 07:00:00&quot;
00000002141C    0000009924F2    80000027133558  t1      &quot;82339012756833423&quot;     &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为396108如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;1970-01-01 07:00:00&quot;
00000002141D    0000009924F2    80000027133568  t1      &quot;8234322198577796&quot;      &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为935297如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;1970-01-01 07:00:00&quot;
00000002141E    0000009924F2    80000027133578  t1      &quot;10235259536125650&quot;     &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为474851如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;1970-01-01 07:00:00&quot;
00000002141F    0000009924F2    80000027133588  t1      &quot;10235353811295807&quot;     &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为444632如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;1970-01-01 07:00:00&quot;
000000021420    0000009924F2    80000027133598  t1      &quot;102354211240398235&quot;    &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为478503如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;1970-01-01 07:00:00&quot;
000000021421    0000009924F2    800000271335A8  t1      &quot;102354554052884567&quot;    &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为216825如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;1970-01-01 07:00:00&quot;
000000021422    0000009924F2    800000271335B8  t1      &quot;132213454294519126&quot;    &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为854812如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;1970-01-01 07:00:00&quot;
000000021423    0000009924F2    800000271335C8  t1      &quot;82329022242584577&quot;     &quot;SDK-BBX-010-18681&quot;     &quot;13718311436&quot;   8       &quot;尊敬的用户您好：您的手机验证码为253127如非本人操作，请拨打奥
斯卡客服：400-620-7575。&quot;       &quot;2010-01-01 00:00:00&quot;   0       &quot;2015-08-26 22:02:17&quot;
…………
[root@web103 mysql_recovery]# cat /tmp/2.txt|grep  -v &quot;Page id:&quot;|wc -l
380731
</pre>
<p>因为没有主键,使得恢复出来记录可能有一些重复,整体而言,可以较为完美的恢复数据</p>
<div id="crp_related"><ul><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2015/08/mysql%e5%bc%82%e5%b8%b8%e6%81%a2%e5%a4%8dmysql-drop-table-recovery.html" rel="bookmark" class="crp_title">[MySQL异常恢复]mysql drop table 数据恢复</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2015/08/mysql%e5%bc%82%e5%b8%b8%e6%81%a2%e5%a4%8dmysql-delete-%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d.html" rel="bookmark" class="crp_title">[MySQL异常恢复]mysql delete 数据恢复</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2015/08/mysql-recovery-support.html" rel="bookmark" class="crp_title">MySQL drop database恢复(恢复方法同样适用MySQL drop table,delete,truncate table)</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2014/12/%e4%bd%bf%e7%94%a8%e5%b7%a5%e5%85%b7%e7%9b%b4%e6%8e%a5%e6%8a%bd%e5%8f%96mysql%e6%95%b0%e6%8d%ae%e5%ad%97%e5%85%b8.html" rel="bookmark" class="crp_title">[MySQL异常恢复]使用工具直接抽取MySQL数据字典</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2010/08/fckeditor%e4%bd%bf%e7%94%a8%e8%af%b4%e6%98%8e.html" rel="bookmark" class="crp_title">fckeditor使用说明</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/01/%e8%b7%b3%e8%bf%87obj%e5%9d%8f%e5%9d%97%e6%96%b9%e6%b3%95.html" rel="bookmark" class="crp_title">跳过obj$坏块方法</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/02/%e9%80%9a%e8%bf%87sql%e6%9f%a5%e8%af%a2rman%e5%a4%87%e4%bb%bd%e4%bf%a1%e6%81%af.html" rel="bookmark" class="crp_title">通过sql查询rman备份信息</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2010/09/shell%e7%bc%96%e7%a8%8b%e2%80%94%e2%80%94%e5%9f%ba%e6%9c%ac%e8%af%ad%e6%b3%95.html" rel="bookmark" class="crp_title">shell编程——基本语法</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2013/08/oracle-12c-dbms_utility-expand_sql_text-%e6%9f%a5%e7%9c%8bsql%e8%a7%86%e5%9b%be%e5%9f%ba%e8%a1%a8.html" rel="bookmark" class="crp_title">ORACLE 12C dbms_utility.expand_sql_text 查看SQL视图基表</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2016/06/oracle-dul-11-released.html" rel="bookmark" class="crp_title">oracle dul 11 正式发布</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2012/09/bbed_wrap%e8%84%9a%e6%9c%ac%e8%8e%b7%e5%8f%96%e6%95%b0%e6%8d%ae%e5%9d%97%e5%86%85%e5%ae%b9.html" rel="bookmark" class="crp_title">bbed_wrap脚本获取数据块内容</a></li><li style="list-style-type:decimal;font-size:11px;" ><a href="https://www.xifenfei.com/2011/08/%e5%9c%a8%e7%ba%bf%e9%87%8d%e5%ae%9a%e4%b9%89%e5%8e%9f%e7%90%86%e6%8e%a2%e8%ae%a8.html" rel="bookmark" class="crp_title">在线重定义原理探讨</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>https://www.xifenfei.com/2015/08/mysql%e5%bc%82%e5%b8%b8%e6%81%a2%e5%a4%8d%e6%97%a0%e4%b8%bb%e9%94%ae%e6%83%85%e5%86%b5%e4%b8%8binnodb%e6%95%b0%e6%8d%ae%e6%81%a2%e5%a4%8d.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
