# binlog 为 ROW 格式 # 1.不使用 use db mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 154 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ mysql> select database (); + ------------+ | database () | + ------------+ | NULL | + ------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE testdb.`test_tb1` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.06 sec) mysql> insert into testdb.test_tb1 values (1001, 'sdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 653 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE logdb.`log_tb1` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> insert into logdb.log_tb1 values (1001, 'sdfde' ); Query OK, 1 row affected (0.00 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 883 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ mysql> insert into logdb.log_tb1 values (1002, 'sdsdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 883 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ mysql> alter table logdb.log_tb1 add column c3 varchar (20); Query OK, 0 rows affected (0.12 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1070 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ # 结论:其他库记录正常 logdb库会记录DDL 不记录DML # 2.使用 use testdb跨库 mysql> use testdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select database (); + ------------+ | database () | + ------------+ | testdb | + ------------+ 1 row in set (0.00 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1070 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE `test_tb2` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> insert into test_tb2 values (1001, 'sdfde' ); Query OK, 1 row affected (0.04 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1574 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE logdb.`log_tb2` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1810 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> insert into logdb.log_tb2 values (1001, 'sdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1810 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) # 结论:同样logdb库会记录DDL 不记录DML # 3.使用 use logdb跨库 mysql> use logdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select database (); + ------------+ | database () | + ------------+ | logdb | + ------------+ 1 row in set (0.00 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1810 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE testdb.`test_tb3` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.23 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 1810 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> insert into testdb.test_tb3 values (1001, 'sdfde' ); Query OK, 1 row affected (0.02 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2081 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE `log_tb3` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2081 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> insert into log_tb3 values (1001, 'sdfde' ); Query OK, 1 row affected (0.02 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2081 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) # 结论:logdb都不记录 同时不记录其他库的DDL # 4.每次操作都进入此库 不跨库 mysql> use testdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2081 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> CREATE TABLE `test_tb4` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.05 sec) mysql> insert into test_tb4 values (1001, 'sdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2585 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> use logdb; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> CREATE TABLE `log_tb4` ( id int , name varchar (30) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Query OK, 0 rows affected (0.04 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2585 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) mysql> insert into log_tb4 values (1001, 'sdfde' ); Query OK, 1 row affected (0.01 sec) mysql> show master status; + ---------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------+----------+--------------+------------------+-------------------+ | binlog.000011 | 2585 | | logdb | | + ---------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec) # 结论:其他库全部记录 logdb全不记录 |