DBA---------------------------数据库--------------------通过文件恢复数据库

 

文件恢复数据库文件

1. 创建数据库

USE world_x;
CREATE TABLE t100 (`id` int(11) DEFAULT NULL,\
`num` int(11) DEFAULT NULL,\
`k1` char(2) COLLATE utf8mb4_bin DEFAULT NULL,\
`k2` char(4) COLLATE utf8mb4_bin DEFAULT NULL,\
`dt` timestamp NOT NULL, key index_c(k2))
charset=utf8mb4;

2.删除表空间

alter table  confulence.t1 discard tablespace;

3.拷贝数据ibd文件

cp t100w.ibd ../world_x/

4.调整文件属主

chown -R mysql.mysql t100.ibd

5.导入表空间

alter table  confulence.t1 import tablespace;

 

--------批量表空间删除。

select concat('alter table ',table_schema,'.'table_name,' discard tablespace;') from information_schema.tables where table_schema='world' into outfile '/tmp/discad.sql';
source /tmp/discard.sql

--------- 跳过外键检查。

set foreign_key_checks=0 

----------拷贝生产中world库下的所有表的ibd文件拷贝到准备好的环境中

select concat('alter table ',table_schema,'.'table_name,' import tablespace;') from information_schema.tables where table_schema='world' into outfile '/tmp/import.sql';

 

posted @ 2019-09-14 21:24  lyh3420  阅读(102)  评论(0)    收藏  举报