内容简介:删除 MySQL 表中的数据mysql> use sbtest;mysql> select count(*) from sbtest1;
删除 MySQL 表中的数据
mysql> use sbtest;
mysql> select count(*) from sbtest1;
+----------+
| count(*) |
+----------+
| 1000 |
+----------+
1 row in set (0.00 sec)
mysql> delete from sbtest1;
Query OK, 1000 rows affected (0.21 sec)
mysql> select count(*) from sbtest1;
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.00 sec)
确认时间点和当前二进制日志文件,从二进制日志中读取操作记录
mysqlbinlog \
--start-datetime="2018-09-27 15:55:00" \
--stop-datetime="2018-09-27 15:00:00" \
--base64-output=decode-rows \
--result-file=result.sql \
-v /var/lib/mysql/binlog.000022
其中的一条记录
去除不相关的内容
grep -A 5 "DELETE FROM \`sbtest\`.\`sbtest1\`" result.sql > 1.txt
提取数据
grep "=" 1.txt > 2.txt
sed -i 's/### //g' 2.txt
使用以下脚本生成 INSERT 语句
[root@mysql03 tmp]# cat r2.sh
#!/bin/bash
vs=""
while read line
do
n=`echo $line | awk -NF "=" '{print $1}'`
v=`echo $line | awk -NF "=" '{print $2}'`
if [ "$n" = "@1" ]; then
vs="INSERT INTO \`sbtest\`.\`sbtest1\` VALUES("$v
elif [ "$n" = "@2" ]; then
vs=$vs" , "$v
elif [ "$n" = "@3" ]; then
vs=$vs" , "$v
elif [ "$n" = "@4" ]; then
vs=$vs" , "$v");"
echo $vs >> 3.txt
fi
done < 2.txt
[root@mysql03 tmp]# sh r2.sh
将数据导入到 MySQL 表中
[root@mysql03 tmp]# mysql < 3.txt
mysql> select count(*) from sbtest1;
+----------+
| count(*) |
+----------+
| 1000 |
+----------+
1 row in set (0.00 sec)
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Large-Scale Inference
Bradley Efron / Cambridge University Press / 2010-8-5 / GBP 48.00
We live in a new age for statistical inference, where modern scientific technology such as microarrays and fMRI machines routinely produce thousands and sometimes millions of parallel data sets, each ......一起来看看 《Large-Scale Inference》 这本书的介绍吧!