[root@MariaDB ~]# service mysqld stop
MySQL server PID file could not be found!? ? ? ? ? ? ? ? ? [FAILED]
[root@MariaDB ~]# killall mysqld
mysqld: no process killed
从二进制日志文件中导出所有和hellodb数据库相关的操作。
导出之前需要去掉误删除语句,查看语句在二进制日志文件中的记录位置
MariaDB [(none)]> show binlog events in'mysql-bin.000002'\G;
*************************** 7. row***************************
? Log_name:mysql-bin.000003
? ? ? ? Pos:642
?Event_type:Query
? Server_id:1
End_log_pos: 729
? ? ? Info:drop database hellodb
7 rows in set (0.00 sec)
得到语句记录位置之后,不导出记录删除位置
[root@Mariadb ~]# mysqlbinlog --stop-position=729/mydata/data/mysql-bin.000002 > /backup/lvm.sql
复制所有备份的文件和目录到数据目录下
[root@MariaDB ~]# cp -a /backup/mariadb-all-2015-05-28-02-57-51/*/mydata/data/
[root@MariaDB ~]# ll /mydata/data/
total 28764
-rw-rw---- 1 mysql mysql? ? 16384 May 27 22:30 aria_log.00000001
-rw-rw---- 1 mysql mysql? ? ? 52 May 27 22:30 aria_log_control
drwx------ 2 mysql mysql? ? 4096 May 28 00:49 hellodb
-rw-rw---- 1 mysql mysql 18874368 May 28 00:49ibdata1
-rw-rw---- 1 mysql mysql? 5242880 May 28 00:49 ib_logfile0
-rw-rw---- 1 mysql mysql? 5242880 May 27 22:34 ib_logfile1
-rw-r----- 1 mysql root? ? ? 5674 May 28 00:43 MariaDB.err
-rw-rw---- 1 mysql mysql? ? ? ? 5May 28 00:43 MariaDB.pid
drwx------ 2 mysql root? ? ? 4096 May 27 22:30 mysql
-rw-rw---- 1 mysql mysql? ? ? 632 May 27 23:12 mysql-bin.000001
-rw-rw---- 1 mysql mysql? ? 8667 May 27 23:22 mysql-bin.000002
-rw-rw---- 1 mysql mysql? ? ? 114 May 28 00:50 mysql-bin.index
drwx------ 2 mysql mysql? ? 4096 May 27 22:30 performance_schema
drwx------ 2 mysql root? ? ? 4096 May 27 22:30 test
这个时候启动mysqld服务就可以看到备份之前的数据了
[root@MariaDB ~]# mysql -u root -p
MariaDB [(none)]> use hellodb;
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes? ? ? ? ? |
| coc? ? ? ? ? ? ? |
| courses? ? ? ? ? |
| scores? ? ? ? ? |
| students? ? ? ? |
| tb1? ? ? ? ? ? ? |
| teachers? ? ? ? |
| toc? ? ? ? ? ? ? |
+-------------------+
MariaDB [hellodb]> select * from tb1;
+------+
| id? |
+------+
|? ? 1 |
|? ? 2 |
|? ? 3 |
|? 21 |
|? 22 |
|? 23 |
+------+
6 rows in set (0.01 sec)
恢复的数据只是备份之前的数据,备份之后更改的数据还没有回了,这个时候就需要导入二进制日志转换成的sql文件了
[root@MariaDB ~]# mysql -u root -p
查看数据就可以看到tb2了
MariaDB [hellodb]> show tables;
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes? ? ? ? ? |
| coc? ? ? ? ? ? ? |
| courses? ? ? ? ? |
| scores? ? ? ? ? |
| students? ? ? ? |
| tb2? ? ? ? ? ? ? |
| teachers? ? ? ? |
| toc? ? ? ? ? ? ? |
+-------------------+
MariaDB [hellodb]> select * from tb2;
+------+
| id? |
+------+
|? ? 1 |
|? ? 2 |
|? ? 3 |
+------+