MySQL binlog 日志内容导出规则处理 发表于 2016-11-03 | 分类于 php | | 阅读次数 由于误删了mysql的数据,通过binlog导出的数据匹配写入的sql,代码如: 12345678910111213141516171819202122$str = file_get_contents('test.log');// $str = <<<EOF// use `dswfnet_anru`/*!*/;// SET TIMESTAMP=1473609850/*!*/;// INSERT INTO `sp_active_info` (`code`,`phone`,`name`,`province`,`city`,`area`,`addr`,`ua`,`ip`,`insert_time`) VALUES ('8225','18778780399','卢秋燕','广西区','钦州市','钦南区','广西钦州市北部湾大道','Mozilla/5.0 (Linux; Android 4.3; R7007 Build/JLS36C) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036558 Safari/537.36 MicroMessenger/6.3.23.840 NetType/cmnet Language/zh_CN','117.136.98.157','2016-09-12 00:04:10')// /*!*/;// # at 16267863// EOF;$patten = '#(INSERT INTO `sp_active_info`.+)#i';preg_match_all($patten, $str, $match);echo count($match[1]);foreach($match[1] as $v){ $v = $v.';'."\n"; file_put_contents('test.sql', $v,FILE_APPEND );}