mysql,mariadbライブラリ削除、リカバリの完全なシミュレーション実装
10167 ワード
シミュレーションシーン:
注意:
処理ロジック:
シミュレーション障害:
-- 10:00 db1,-- 10:10 , ?
注意:
, db1 , db2, ,
, , ;
; , , ,
, 。
処理ロジック:
1、 : , ;
2、 :
: ;
1 10:00 ; SQL ;
10:00 - 10:10 ;
, , 1 10:00 。
[root@centos7x ~]$mysqldump -A -F --master-data=2 --single-transaction > all_`date +%F_%T`.sql
[root@centos7x ~]$less all_2018-02-24_21\:46\:13.sql
-- Position to start replication or point-in-time recovery from
--
-- CHANGE MASTER TO MASTER_LOG_FILE='mariadb-bin.000010', MASTER_LOG_POS=245;
--
-- Current Database: `hellodb`
,'mariadb-bin.000010', MASTER_LOG_POS=245 ;
,--master-data=1 2 ; 1;
シミュレーション障害:
;
MariaDB [hellodb]> select * from students;
+-------+---------------+-----+--------+---------+-----------+
| StuID | Name | Age | Gender | ClassID | TeacherID |
+-------+---------------+-----+--------+---------+-----------+
| 1 | Shi Zhongyu | 22 | M | 2 | 3 |
| 2 | Shi Potian | 22 | M | 1 | 7 |
| 3 | Xie Yanke | 53 | M | 2 | 16 |
| 4 | Ding Dian | 32 | M | 4 | 4 |
| 5 | Yu Yutong | 26 | M | 3 | 1 |
| 6 | Shi Qing | 46 | M | 5 | NULL |
| 7 | Xi Ren | 19 | F | 3 | NULL |
| 8 | Lin Daiyu | 17 | F | 7 | NULL |
| 9 | Ren Yingying | 20 | F | 6 | NULL |
| 10 | Yue Lingshan | 19 | F | 3 | NULL |
| 11 | Yuan Chengzhi | 23 | M | 6 | NULL |
| 12 | Wen Qingqing | 19 | F | 1 | NULL |
| 13 | Tian Boguang | 33 | M | 2 | NULL |
| 14 | Lu Wushuang | 17 | F | 3 | NULL |
| 15 | Duan Yu | 19 | M | 4 | NULL |
| 16 | Xu Zhu | 21 | M | 1 | NULL |
| 17 | Lin Chong | 25 | M | 4 | NULL |
| 18 | Hua Rong | 23 | M | 7 | NULL |
| 19 | Xue Baochai | 18 | F | 6 | NULL |
| 20 | Diao Chan | 19 | F | 7 | NULL |
| 21 | Huang Yueying | 22 | F | 6 | NULL |
| 22 | Xiao Qiao | 20 | F | 1 | NULL |
| 23 | Ma Chao | 23 | M | 4 | NULL |
| 24 | Xu Xian | 27 | M | NULL | NULL |
| 25 | Sun Dasheng | 100 | M | NULL | NULL |
+-------+---------------+-----+--------+---------+-----------+
25 rows in set (0.00 sec)
MariaDB [hellodb]> insert into students (name,age,gender) values('a','29','F');
Query OK, 1 row affected (0.01 sec)
MariaDB [hellodb]> select * from students;
+-------+---------------+-----+--------+---------+-----------+
| StuID | Name | Age | Gender | ClassID | TeacherID |
+-------+---------------+-----+--------+---------+-----------+
| 1 | Shi Zhongyu | 22 | M | 2 | 3 |
| 2 | Shi Potian | 22 | M | 1 | 7 |
| 3 | Xie Yanke | 53 | M | 2 | 16 |
| 4 | Ding Dian | 32 | M | 4 | 4 |
| 5 | Yu Yutong | 26 | M | 3 | 1 |
| 6 | Shi Qing | 46 | M | 5 | NULL |
| 7 | Xi Ren | 19 | F | 3 | NULL |
| 8 | Lin Daiyu | 17 | F | 7 | NULL |
| 9 | Ren Yingying | 20 | F | 6 | NULL |
| 10 | Yue Lingshan | 19 | F | 3 | NULL |
| 11 | Yuan Chengzhi | 23 | M | 6 | NULL |
| 12 | Wen Qingqing | 19 | F | 1 | NULL |
| 13 | Tian Boguang | 33 | M | 2 | NULL |
| 14 | Lu Wushuang | 17 | F | 3 | NULL |
| 15 | Duan Yu | 19 | M | 4 | NULL |
| 16 | Xu Zhu | 21 | M | 1 | NULL |
| 17 | Lin Chong | 25 | M | 4 | NULL |
| 18 | Hua Rong | 23 | M | 7 | NULL |
| 19 | Xue Baochai | 18 | F | 6 | NULL |
| 20 | Diao Chan | 19 | F | 7 | NULL |
| 21 | Huang Yueying | 22 | F | 6 | NULL |
| 22 | Xiao Qiao | 20 | F | 1 | NULL |
| 23 | Ma Chao | 23 | M | 4 | NULL |
| 24 | Xu Xian | 27 | M | NULL | NULL |
| 25 | Sun Dasheng | 100 | M | NULL | NULL |
| 26 | a | 29 | F | NULL | NULL |
+-------+---------------+-----+--------+---------+-----------+
26 rows in set (0.00 sec)
MariaDB [hellodb]>
MariaDB [hellodb]> drop database hellodb ;
Query OK, 7 rows affected (0.01 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use test;
Database changed
MariaDB [test]> create table t1(id int);
Query OK, 0 rows affected (0.01 sec)
MariaDB [test]> select * from test;
ERROR 1146 (42S02): Table 'test.test' doesn''t exist
MariaDB [test]>
MariaDB [test]> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t1 |
+----------------+
1 row in set (0.00 sec)
MariaDB [test]> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> select * from t1;
Empty set (0.00 sec)
MariaDB [test]> insert t1 values(1);
ERROR 1223 (HY000): Can''t execute the query because you have a conflicting read lock
MariaDB [test]>
:
MariaDB [test]> show master logs;
+--------------------+-----------+
| Log_name | File_size |
+--------------------+-----------+
| mariadb-bin.000001 | 7700 |
| mariadb-bin.000002 | 290 |
| mariadb-bin.000003 | 290 |
| mariadb-bin.000004 | 290 |
| mariadb-bin.000005 | 290 |
| mariadb-bin.000006 | 290 |
| mariadb-bin.000007 | 290 |
| mariadb-bin.000008 | 290 |
| mariadb-bin.000009 | 290 |
| mariadb-bin.000010 | 669 |
+--------------------+-----------+
10 rows in set (0.00 sec)
:
'mariadb-bin.000010', MASTER_LOG_POS=245 ;
'mariadb-bin.000010', MASTER_LOG_POS=245 'mariadb-bin.000011', MASTER_LOG_POS=245
;
MariaDB [test]> flush logs;
Query OK, 0 rows affected (0.01 sec)
MariaDB [test]> show master logs;
+--------------------+-----------+
| Log_name | File_size |
+--------------------+-----------+
| mariadb-bin.000001 | 7700 |
| mariadb-bin.000002 | 290 |
| mariadb-bin.000003 | 290 |
| mariadb-bin.000004 | 290 |
| mariadb-bin.000005 | 290 |
| mariadb-bin.000006 | 290 |
| mariadb-bin.000007 | 290 |
| mariadb-bin.000008 | 290 |
| mariadb-bin.000009 | 290 |
| mariadb-bin.000010 | 714 |
| mariadb-bin.000011 | 245 |
+--------------------+-----------+
11 rows in set (0.01 sec)
, , ;
[root@centos7x ~]$cp /var/lib/mysql/mariadb-bin.000010 .
[root@centos7x ~]$ls
all_2018-02-24_21:46:13.sql all.sql anaconda-ks.cfg hellodb_InnoDB.sql initial-setup-ks.cfg mariadb-bin.000010
[root@centos7x ~]$mysqlbinlog --start-position=245 mariadb-bin.000010
[root@centos7x ~]$mysqlbinlog --start-position=245 mariadb-bin.000010 > binlog.sql
SQL ;
[root@centos7x ~]$vim binlog.sql
drop database hellodb
;
MariaDB [test]> show variables like 'sql_log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_log_bin | ON |
+---------------+-------+
1 row in set (0.00 sec)
MariaDB [test]> set sql_log_bin=0;
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> show variables like 'sql_log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_log_bin | OFF |
+---------------+-------+
1 row in set (0.00 sec)
sql_log_bin /etc/my.cnf log_bin , , ,
; log_bin , MySQL ;
sql_log_bin , ;
;
MariaDB [test]> unlock tables ;
Query OK, 0 rows affected (0.01 sec)
:
MariaDB [test]> source all_2018-02-24_21:46:13.sql
MariaDB [(none)]> select * from hellodb.students;
:
, ;
MariaDB [(none)]> source binlog.sql
MariaDB [(none)]> select * from hellodb.students;
| 25 | Sun Dasheng | 100 | M | NULL | NULL |
| 26 | a | 29 | F | NULL | NULL |
+-------+---------------+-----+--------+---------+-----------+
MariaDB [test]> set sql_log_bin=1;
Query OK, 0 rows affected (0.00 sec)
MariaDB [test]> show variables like 'sql_log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_log_bin | ON |
+---------------+-------+
1 row in set (0.00 sec)