标签:mysql-bin info inf use 目标 数据 理解 gad 备份与恢复
MySQL增量备份与恢复某公司用户信息数据库为client,用户资源表为user_info
(1):请为该公司每周进行完全备份
(2):每天为该公司进行增量备份
(3):新增加用户信息如下
id | name | zifei |
---|---|---|
1 | wang-1 | 10 |
2 | wang-2 | 20 |
#1:先把下列原有的表进行完全备份在备份前先刷新一次
[root@localhost data] mysqladmin -u root -p flush-logs
mysql> select * from user_info;
+------+---------+-------+
| id | name | zifei |
+------+---------+-------+
| 1 | zhang-1 | 10 |
| 2 | zhang-2 | 20 |
| 3 | zhang-3 | 5 |
+------+---------+-------+
3 rows in set (0.00 sec)
[root@localhost data] mysqldump -u root -p client user_info > /usr/local/mysql/data/client-user_info.sql
Enter password
[root@localhost data] ls
client-user_info.sql
#2:添加wang-1信息后进行增量备份
mysql> insert into user_info (id,name,zifei) values (4,‘wang-1‘,10);
Query OK, 1 row affected (0.00 sec)
[root@localhost data] mysqladmin -uroot -p flush-logs
Enter password: #上面的命令刷新保存在mysql-bin.000001里面
[root@localhost data]# ls # mysql-bin.000002是 mysql-bin.000001保存之后会生成一个空的日志等待下一次增量备份
mysql-bin.000001
mysql-bin.000002
#3:添加wang-2的信息后进行增量备份
mysql> insert into user_info (id,name,zifei) values (5,‘wang-2‘,20);
Query OK, 1 row affected (0.00 sec)
[root@localhost data] mysqladmin -uroot -p flush-logs
Enter password:
[root@localhost data]# ls
mysql-bin.000002
mysql-bin.000003
#下表中wang-1,wang-2已被删除
mysql> select * from user_info;
+------+---------+-------+
| id | name | zifei |
+------+---------+-------+
| 1 | zhang-1 | 10 |
| 2 | zhang-2 | 20 |
| 3 | zhang-3 | 5 |
+------+---------+-------+
5 rows in set (0.00 sec)
#恢复wang-1
[root@localhost data] mysqlbinlog --no-defaults mysql-bin.000002 | mysql -u root -p
#先恢复mysql-bin.000002我们看一下
mysql> select * from user_info;
+------+---------+-------+
| id | name | zifei |
+------+---------+-------+
| 1 | zhang-1 | 10 |
| 2 | zhang-2 | 20 |
| 3 | zhang-3 | 5 |
| 5 | wang-2 | 20 |
+------+---------+-------+
4 rows in set (0.00 sec)
#恢复的是我最后一次操作备份wang-2的数据
#恢复mysql-bin.000001看一下
[root@localhost data]# mysqlbinlog --no-defaults mysql-bin.000001 | mysql -u root -p
mysql> select * from user_info;
+------+---------+-------+
| id | name | zifei |
+------+---------+-------+
| 1 | zhang-1 | 10 |
| 2 | zhang-2 | 20 |
| 3 | zhang-3 | 5 |
| 4 | wang-2 | 10 |
| 5 | wang-2 | 20 |
+------+---------+-------+
4 rows in set (0.00 sec)
[root@localhost data] mysqlbinlog --no-defaults mysql-bin.000001
BINLOG ‘ #下面加密的哪一行就是你在数据库进行操作
PCE7WxMBAAAAOgAAAEkIAAAAANsAAAAAAAEABmNsaWVudAAJdXNlcl9pbmZvAAMDDwMCHgAH7bXH
3w==
PCE7WyABAAAAMwAAAHwIAAAAANsAAAAAAAEAAgAD//gFAAAABndhbmctMhQAAABJK6gI
‘/*!*/;
# at 2172
#想要解密这个加密文件用下列语句
[root@localhost data] mysqlbinlog --no-defaults --base64-output=decode-rows -v mysql-bin.000001
### DELETE FROM `client`.`user_info`
### WHERE #下面就是之前看不到的加密的部分
### @1=5
### @2=‘wang-2‘
### @3=20
标签:mysql-bin info inf use 目标 数据 理解 gad 备份与恢复
原文地址:http://blog.51cto.com/13645280/2135621