mysql从.frm和.ibd文件恢复数据库
2016-03-21 11:19
471 查看
下载
需要安装https://www.microsoft.com/en-us/download/details.aspx?id=40784
1、管理员打开cmd,使用mysqlfrm.exe工具恢复出表的创建语句
mysqlfrm --server=user:pwd@localhost --port=3307 "path_to_.frm_file" > table_name.txt
2、建立同名数据库
3、在数据库下根据之前的建表语句创建表
如果报错11:01:37 ALTER TABLE tbl import TABLESPACE Error Code: 1808. Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd file has ROW_TYPE_COMPACT row format.) 0.172 sec
则在建表语句后加上 ROW_FORMAT=COMPACT
4、使用ALTER TABLE table_name DISCARD TABLESPACE;删除新的.ibd文件
5、复制备份的.ibd文件到新建立的表目录下
6、ALTER TABLE table_Name IMPORT TABLESPACE;恢复数据
Download and install the MySQL utilities at -> http://dev.mysql.com/downloads/utilities. Go into your command/terminal to open the MySQL utility, mysqlfrm, and use it to find the structure of your table that you need to restore. How I did that, was I cd'ed into the file location of mysqlfrm, then entered "mysqlfrm --server=user:pwd@localhost
--port=3307 "path_to_.frm_file" > table_name.txt". The .txt file should be saved in the same folder as where your utilities are saved if you didn't specify where you wanted it to go.
In the text file, you'll see the CREATE TABLE statements, that include all the columns and info (basically, the original structure) of your table. Copy that CREATE statement with all that info.
In your MySQL Command, create a new database (CREATE DATABASE database_name). Make it the same name as your original database name.
Create a new table inside the new database--it doesn't have to be the same name as the folder. You can create the new table inside the command prompt, but I created my table in PhpMyAdmin, a free software tool that handles the administration of MySQL over
the web. I simply clicked on the database on PhpMyAdmin, then the SQL table, and pasted the table structure from #3. (As a side note, I always received errors if I named my tables "table" in my command prompt, so try to avoid that name).
On your MySQL Command, go into your database, and enter "ALTER TABLE table_name DISCARD TABLESPACE", which will essentially remove this table's .ibd file.
Copy your original table (the table you want to restore)'s .ibd file into the newly-created table to replace the .ibd file that you just removed. Change your initial .ibd file to the newly created table's name. This will mimic the old .ibd file that you
just deleted. You can find this folder in the MySQL data folder, under the newly-created database folder on your computer.
Go back to your MySQL Command, go into your database, and enter "ALTER TABLE table_Name IMPORT TABLESPACE." You'll receive a "warning" (1) error-type statement, but just ignore that.
And done! if you try to access your new table, it should contain all the data from your old table.
参考
http://dba.stackexchange.com/questions/71596/restoring-mysql-tables-from-ibd-frm-and-mysqllogbin-files
MySQL Utilities
http://dev.mysql.com/downloads/utilities/需要安装https://www.microsoft.com/en-us/download/details.aspx?id=40784
1、管理员打开cmd,使用mysqlfrm.exe工具恢复出表的创建语句
mysqlfrm --server=user:pwd@localhost --port=3307 "path_to_.frm_file" > table_name.txt
2、建立同名数据库
3、在数据库下根据之前的建表语句创建表
如果报错11:01:37 ALTER TABLE tbl import TABLESPACE Error Code: 1808. Schema mismatch (Table has ROW_TYPE_DYNAMIC row format, .ibd file has ROW_TYPE_COMPACT row format.) 0.172 sec
则在建表语句后加上 ROW_FORMAT=COMPACT
4、使用ALTER TABLE table_name DISCARD TABLESPACE;删除新的.ibd文件
5、复制备份的.ibd文件到新建立的表目录下
6、ALTER TABLE table_Name IMPORT TABLESPACE;恢复数据
Download and install the MySQL utilities at -> http://dev.mysql.com/downloads/utilities. Go into your command/terminal to open the MySQL utility, mysqlfrm, and use it to find the structure of your table that you need to restore. How I did that, was I cd'ed into the file location of mysqlfrm, then entered "mysqlfrm --server=user:pwd@localhost
--port=3307 "path_to_.frm_file" > table_name.txt". The .txt file should be saved in the same folder as where your utilities are saved if you didn't specify where you wanted it to go.
In the text file, you'll see the CREATE TABLE statements, that include all the columns and info (basically, the original structure) of your table. Copy that CREATE statement with all that info.
In your MySQL Command, create a new database (CREATE DATABASE database_name). Make it the same name as your original database name.
Create a new table inside the new database--it doesn't have to be the same name as the folder. You can create the new table inside the command prompt, but I created my table in PhpMyAdmin, a free software tool that handles the administration of MySQL over
the web. I simply clicked on the database on PhpMyAdmin, then the SQL table, and pasted the table structure from #3. (As a side note, I always received errors if I named my tables "table" in my command prompt, so try to avoid that name).
On your MySQL Command, go into your database, and enter "ALTER TABLE table_name DISCARD TABLESPACE", which will essentially remove this table's .ibd file.
Copy your original table (the table you want to restore)'s .ibd file into the newly-created table to replace the .ibd file that you just removed. Change your initial .ibd file to the newly created table's name. This will mimic the old .ibd file that you
just deleted. You can find this folder in the MySQL data folder, under the newly-created database folder on your computer.
Go back to your MySQL Command, go into your database, and enter "ALTER TABLE table_Name IMPORT TABLESPACE." You'll receive a "warning" (1) error-type statement, but just ignore that.
And done! if you try to access your new table, it should contain all the data from your old table.
参考
http://dba.stackexchange.com/questions/71596/restoring-mysql-tables-from-ibd-frm-and-mysqllogbin-files
相关文章推荐
- MySQL中的各种引擎
- MySQL中比like语句更高效的写法locate position instr find_in_set
- CDH5.1.0 HIVE mysql 配置远程元数据库
- mysql 中的varchar255 uft-8 的格式到底能放多少汉字
- DedeCMS下data日志mysql_error_trace.inc暴露后台地址
- mysql函数大全
- 实现 win2003 下 mysql 数据库每天自动备份
- 23个MySQL常用查询语句
- 如何修改MySQL的默认ID号排序? [
- MySQL Order By Rand()效率
- Mysql提权
- 【转载】Mysql警告:could not be resolved: getnameinfo() returned error (code: 11004)
- mysql中You can\'t specify target table for update in FROM clause错误
- 批量mysql修改表前缀
- mysql为什么默认有那么多root用户,还有用户名为空的用户?
- mysql 5.1 到 mysql 5.2的出现的索引BTREE问题 use near \'USING BTREE,
- MySql常用命令总结
- Mysql的用户问题 里面有3个root账户
- MySQL 数据库 InnoDB 和 MyISAM 数据引擎的差别
- mysql导入数据时 USING BTREE 错误解决办法