1 2 3 4 5 6 7 8 9 10 11 12 |
InnoDB: Some operating system error numbers are described at InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html 2021-12-02 15:19:55 9272 [ERROR] InnoDB: Could not find a valid tablespace file for 'testdb/wp_10119_term_relationships'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue. 2021-12-02 15:19:55 9272 [ERROR] InnoDB: Tablespace open failed for '"testdb"."wp_10119_term_relationships"', ignored. 2021-12-02 15:19:55 508c InnoDB: Operating system error number 2 in a file operation. InnoDB: Some operating system error numbers are described at InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html 2021-12-02 15:19:55 9272 [ERROR] InnoDB: Could not find a valid tablespace file for 'testdb/wp_10119_term_taxonomy'. See http://dev.mysql.com/doc/refman/5.6/en/innodb-troubleshooting-datadict.html for how to resolve the issue. 2021-12-02 15:19:55 9272 [ERROR] InnoDB: Tablespace open failed for '"testdb"."wp_10119_term_taxonomy"', ignored. 2021-12-02 15:19:55 508c InnoDB: Operating system error number 2 in a file operation. InnoDB: Some operating system error numbers are described at InnoDB: http://dev.mysql.com/doc/refman/5.6/en/operating-system-error-codes.html |
Tablespace Does Not Exist
With innodb_file_per_table
enabled, the following message might occur if the .frm
or .ibd
files (or both) are missing:
1 2 3 4 5 6 |
InnoDB<span class="token punctuation">:</span> in InnoDB data dictionary has tablespace id <em class="replaceable">N</em><span class="token punctuation">,</span> InnoDB<span class="token punctuation">:</span> but tablespace with that id or name does not exist<span class="token punctuation">.</span> Have InnoDB<span class="token punctuation">:</span> you deleted or moved <span class="token punctuation">.</span>ibd files? InnoDB<span class="token punctuation">:</span> This may also be a table created with CREATE TEMPORARY TABLE InnoDB<span class="token punctuation">:</span> whose <span class="token punctuation">.</span>ibd and <span class="token punctuation">.</span>frm files MySQL automatically removed<span class="token punctuation">,</span> but the InnoDB<span class="token punctuation">:</span> table still exists in the InnoDB internal data dictionary<span class="token punctuation">.</span> |
If this occurs, try the following procedure to resolve the problem:
- Create a matching
.frm
file in some other database directory and copy it to the database directory where the orphan table is located. - Issue
DROP TABLE
for the original table. That should successfully drop the table andInnoDB
should print a warning to the error log that the.ibd
file was missing.
上面大体意思是,比如testdb数据库缺少tbStudent表,那么你可以在别的或新建的数据库当中,创建tbStudent表,比如在SchoolDb数据库中创建的,那么在scholldb数据库的文件夹中会有tbStudent.frm和tbstudent.ibd文件,直接将tbStudent.frm拷贝到testdb数据库的testdb文件夹中,然后在testdb中使用drop table tbstudent命令,就能将不存在的清删掉了。
查询系统表,找到缺少的表:
1 |
SELECT REPLACE(CONCAT("drop table ",NAME,";"),"testdb/","") FROM INFORMATION_SCHEMA.INNODB_SYS_TABLES WHERE NAME LIKE '%wp_%'; |
于是自己写了个程序按照缺少的表名,并复制生成的表:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WinFormsApp2 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Debug.WriteLine("========"); this.ReadTxtContent("d:\\test\\table1.txt"); MessageBox.Show("ok"); } public void ReadTxtContent(string Path) { StreamReader sr = new StreamReader(Path, Encoding.Default); string content; int i = 0; while ((content = sr.ReadLine()) != null) { Debug.WriteLine(content.ToString()); string file = content + ".frm"; File.Copy(@"d:\test\wp_10119_term_taxonomy.frm", "D:\\test\\out\\" + file,false); // if (i++ == 10) // break; } } } } |
发表评论