mysql>USE sakila
mysql>CREATE TABLE actor (
actor_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
first_name VARCHAR(45) NOT NULL,
last_name VARCHAR(45) NOT NULL,
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (actor_id),
KEY idx_actor_last_name (last_name)
)ENGINE=InnoDB DEFAULT CHARSET=utf8
ALTER TABLE {库名}.{表名} DISCARD TABLESPACE
例:
mysql>ALTER TABLE sakila.actor DISCARD TABLESPACE
cp /backup_directory/actor.ibd path/to/mysql-5.7/data/sakila/
ALTER TABLE {库名}.{表名} IMPORT TABLESPACESHOW WARNINGS
例:
mysql>ALTER TABLE sakila.actor IMPORT TABLESPACESHOW WARNINGS
Query OK, 0 rows affected, 1 warning (0.15 sec)
Warning | 1810 | InnoDB: IO Read error: (2, No such file or directory)
Error opening './sakila/actor.cfg', will attempt to import
without schema verification
mysql>SELECT COUNT(*) FROM sakila.actor
+----------+
| count(*) |
+----------+
| 200 |
+----------+
在使用独立表空间的情况下,如果不慎使得innodb存储引擎的元数据文件ibdata损坏,我们还可以挽救宝贵的数据.因为在innodb使用独立表空间的情况下,ibdata文件会记录每个innodb表的id,只要使得ibd中的表id和ibdata文件中记录的表id相同,就能够打开表,读取到数据.
#创建表
CREATE TABLE `ibdtest` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fid` int(11) NOT NULL COMMENT '表b中的id', `content` char(255) NOT NULL COMMENT ' *** 作内容,系统生成', `mark` char(255) NOT NULL COMMENT '备注', PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8
#添加数据INSERT ibdtest (fid,content,mark) VALUES (1,'1','1'),(2,'2','2')SELECT * FROM ibdtest
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)