这篇文章主要介绍了怎么从MySQL全库备份的dump文件中恢复某张表和表结构,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
例如全库dump文件为test.sql
从全库备份test.sql中抽取出t_user_sign表的内容:
[root@linuxidc ~]# grep ‘INSERT INTO `t_user_sign`’ test.sql > /tmp/t_user_sign.sql
INSERT INTO `t_user_sign` VALUES (‘913400007568317795′,’0′,’661401092936′,’20150101000000′,’60.166.38.226′,’2016-11-24 17:24:19′,’
0001221E7FF447FB96111C2510F5B80F’,’74-27-EA-4B-F5-A1′,,…………………………………………………………………………………………………
……………………………………………………………………………………………
从全库备份中test.sql抽取出t_user_sign表的建表结构:
[root@linuxidc ~]# sed -e’/./{H;$!d;}’ -e ‘x;/CREATE TABLE `t_user_sign`/!d;q’ test.sql > /tmp/create.sql
[root@linuxidc ~]# cat /tmp/create.sql
DROP TABLE IF EXISTS `t_user_sign`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_user_sign` (
`SH` varchar(25) DEFAULT NULL COMMENT ‘税号’,
`ZFJH` varchar(20) DEFAULT NULL COMMENT ‘主分机号’,
`KPJH` varchar(20) DEFAULT NULL COMMENT ‘开票机号’,
`FXSJ` varchar(26) DEFAULT NULL COMMENT ‘发行时间’,
`IP` varchar(20) DEFAULT NULL COMMENT ‘客户IP地址’,
`ZCSJ` datetime DEFAULT NULL COMMENT ‘注册时间’,
`ID` varchar(32) NOT NULL COMMENT ‘ID’,
`MAC` varchar(32) DEFAULT NULL COMMENT ‘MAC地址’,
`DQMC` varchar(120) DEFAULT NULL COMMENT ‘地区名称’,
`DQBM` varchar(6) DEFAULT NULL COMMENT ‘地区编码’,
`OS` varchar(120) DEFAULT NULL COMMENT ‘操作系统’,
`SBLX` varchar(120) DEFAULT NULL COMMENT ‘设备类型’,
`WLFWS` varchar(120) DEFAULT NULL COMMENT ‘网络服务商’,
`LATITUDE` varchar(20) DEFAULT NULL COMMENT ‘维度’,
`LONGITUDE` varchar(20) DEFAULT NULL COMMENT ‘经度’,
`NAME` varchar(500) DEFAULT NULL COMMENT ‘企业名称’,
`VERSION` varchar(30) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
根据binlog时间点恢复:
[root@linuxidc ~]# mysqlbinlog –start-datetime=”2017-1-16 19:00:00″ –stop-datetime=”2017-1-16 19:38:00″ mysql-bin.000398 > /tmp/time.sql
[root@idb4 tmp]# more /tmp/time.sql
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#170116 19:37:02 server id 1 end_log_pos 120 CRC32 0x1cf0554e Start: binlog v 4, server v 5.6.27-log created 170116 19:37:02
BINLOG ‘
XrB8WA8BAAAAdAAAAHgAAAAAAAQANS42LjI3LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAEzgNAAgAEgAEBAQEEgAAXAAEGggAAAAICAgCAAAACgoKGRkAAU5V
8Bw=
‘/*!*/;
# at 120
#170116 19:37:02 server id 1 end_log_pos 215 CRC32 0x16c50c8a Query thread_id=238 exec_time=0 error_code=0
SET TIMESTAMP=1484566622/*!*/;
SET @@session.pseudo_thread_id=238/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=1075838976/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\\C latin1 *//*!*/;
SET @@session.character_set_client=8,@@session.collation_connection=8,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
BEGIN
/*!*/;
………………………………………………………………………………………………………………………………………….
感谢你能够认真阅读完这篇文章,希望小编分享的“怎么从MySQL全库备份的dump文件中恢复某张表和表结构”这篇文章对大家有帮助,同时也希望大家多多支持云搜网,关注云搜网行业资讯频道,更多相关知识等着你来学习!