MySQL Multi-Source Replication enables a replication slave to receive transactions from multiple sources simultaneously. Multi-source replication does not implement any conflict detection or resolution when applying the transactions, and those tasks are left to the application if required.

一、问题描述

多源复制,从库在开启复制之前,执行change replication filter replicate_ignore_db=(mysql); 按理应该忽略了mysql库的同步,为什么开启复制之后报错

Last_Error: Error 'Operation CREATE USER failed for 'repl'@'192.168..%'' on query. Default database: ''. Query: 'CREATE USER 'repl'@'192.168..%' IDENTIFIED WITH 'mysql_native_password' AS '*A424E797037BF97C19A2E88CF7891C5C2038C039''

首先怀疑使用了statement格式的日志(binlog_format='STATEMENT'),提问者没有说binlog_format。按照一贯思维,如果binlog_format='ROW',它会检查变更数据所在的database是否匹配过滤选项;如果binlog_format='STATEMENT',它会检查default database(use dbname)是否匹配过滤选项。
第一个推断:binlog_format='STATEMENT',create user语句不是在mysql库下运行~

二、验证推断

2.1、create user

为了验证推断,在自己的一主一从环境(Gtid+Row)测试create user语句

# 从库复制过滤
mydba@192.168.85.133,3306 [(none)]> stop slave sql_thread;
Query OK, 0 rows affected (0.01 sec) mydba@192.168.85.133,3306 [(none)]> change replication filter replicate_ignore_db=(mysql);
Query OK, 0 rows affected (0.00 sec) mydba@192.168.85.133,3306 [(none)]> start slave sql_thread;
Query OK, 0 rows affected (0.01 sec) # 主库Rotate日志
mydba@192.168.85.132,3306 [replcrash]> flush binary logs;
Query OK, 0 rows affected (0.12 sec) mydba@192.168.85.132,3306 [replcrash]> show master status;
+------------------+----------+--------------+------------------+----------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+----------------------------------------------+
| mysql-bin.000108 | 194 | | | 8ab82362-9c37-11e7-a858-000c29c1025c:1-69347 |
+------------------+----------+--------------+------------------+----------------------------------------------+
1 row in set (0.00 sec) mydba@192.168.85.132,3306 [replcrash]> select user,host from mysql.user;
+---------------+--------------+
| user | host |
+---------------+--------------+
| monitor | % |
| mydba | 192.168.85.% |
| repl | 192.168.85.% |
| restoree | 192.168.85.% |
| resolve | db%.zst.com |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| zst | localhost |
+---------------+--------------+
9 rows in set (0.00 sec) # 从库Rotate日志
mydba@192.168.85.133,3306 [replcrash]> flush logs;
Query OK, 0 rows affected (0.07 sec) mydba@192.168.85.133,3306 [replcrash]> show master status;
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------+
| mysql-bin.000021 | 234 | | | 8ab82362-9c37-11e7-a858-000c29c1025c:1-69347,
93f69708-9c39-11e7-b7f8-000c2900c99c:1-284 |
+------------------+----------+--------------+------------------+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec) mydba@192.168.85.133,3306 [replcrash]> select user,host from mysql.user;
+---------------+--------------+
| user | host |
+---------------+--------------+
| monitor | % |
| mydba | 192.168.85.% |
| repl | 192.168.85.% |
| restoree | 192.168.85.% |
| resolve | db%.zst.com |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| zst | localhost |
+---------------+--------------+
9 rows in set (0.02 sec) # 主库创建新用户(注意这里默认的db是replcrash)
mydba@192.168.85.132,3306 [replcrash]> grant select on sakila.* to 'test'@'%' identified by '1234qwer';
Query OK, 0 rows affected, 1 warning (0.06 sec)

从库查看也创建了'test'@'%'用户,binlog_format='ROW',怎么把过滤的mysql库中的create user给传到复制上去了?!

Note
Only DML statements can be logged using the row format. DDL statements are always logged as statements, even when binlog_format=ROW. All DDL statements are therefore always filtered according to the rules for statement-based replication. This means that you must select the default database explicitly with a USE statement in order for a DDL statement to be applied.

前面的grant语句在用户不存在时会创建用户,其实这类DCL语句也是记录为STATEMENT格式。我们注意grant语句默认的db是replcrash,并不是replicate_ignore_db选项中的mysql(虽然grant最终改变的对象是在mysql),所以这条grant语句不会过滤。
如果我们使用:use mysql;grant select on sakila.* to 'test'@'%';默认db变成mysql,符合replicate_ignore_db选项中的mysql过滤条件,这条语句不会被应用到Slave~
如果我们使用:use replcrash;update mysql.user... 由于是ROW格式下的DML操作,语句影响的数据在mysql库,符合replicate_ignore_db选项中的mysql过滤条件,这条语句不会被应用到Slave~

2.2、update 授权表

测试update时忘记where条件,把整个mysql.user的密码给更新了

# 更新用户密码(本意只更新'test'@'%'用户)
mydba@192.168.85.132,3306 [replcrash]> update mysql.user set authentication_string=password('');
Query OK, 10 rows affected, 1 warning (0.02 sec)
Rows matched: 10 Changed: 10 Warnings: 1 mydba@192.168.85.132,3306 [replcrash]> show warnings;
+---------+------+-------------------------------------------------------------------+
| Level | Code | Message |
+---------+------+-------------------------------------------------------------------+
| Warning | 1681 | 'PASSWORD' is deprecated and will be removed in a future release. |
+---------+------+-------------------------------------------------------------------+
1 row in set (0.00 sec)

Changed: 10,再细看把整张表给更新,傻眼+++

# 主库Rotate日志
mydba@192.168.85.132,3306 [replcrash]> flush binary logs; # 查看主库用户信息
mydba@192.168.85.132,3306 [replcrash]> select user,host,authentication_string from mysql.user;
+---------------+--------------+-------------------------------------------+
| user | host | authentication_string |
+---------------+--------------+-------------------------------------------+
| root | localhost | *A4B6157319038724E3560894F7F932C8886EBFCF |
| mysql.session | localhost | *A4B6157319038724E3560894F7F932C8886EBFCF |
| mysql.sys | localhost | *A4B6157319038724E3560894F7F932C8886EBFCF |
| repl | 192.168.85.% | *A4B6157319038724E3560894F7F932C8886EBFCF |
| mydba | 192.168.85.% | *A4B6157319038724E3560894F7F932C8886EBFCF |
| zst | localhost | *A4B6157319038724E3560894F7F932C8886EBFCF |
| resolve | db%.zst.com | *A4B6157319038724E3560894F7F932C8886EBFCF |
| restoree | 192.168.85.% | *A4B6157319038724E3560894F7F932C8886EBFCF |
| monitor | % | *A4B6157319038724E3560894F7F932C8886EBFCF |
| test | % | *A4B6157319038724E3560894F7F932C8886EBFCF |
+---------------+--------------+-------------------------------------------+
10 rows in set (0.00 sec) # 查看从库用户信息
mydba@192.168.85.133,3306 [replcrash]> select user,host,authentication_string from mysql.user;
+---------------+--------------+-------------------------------------------+
| user | host | authentication_string |
+---------------+--------------+-------------------------------------------+
| root | localhost | *A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5 |
| mysql.session | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| repl | 192.168.85.% | *A424E797037BF97C19A2E88CF7891C5C2038C039 |
| mydba | 192.168.85.% | *A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5 |
| zst | localhost | *4E832DC6A6F24719A68C1242068114AA77CA60D0 |
| resolve | db%.zst.com | *A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5 |
| restoree | 192.168.85.% | *A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5 |
| monitor | % | *1975D095AC033CAF4E1BF94F7202A9BBFEEB66F1 |
| test | % | *0CB5F227B3E98395CA0C6F1427427E77ADF49F89 |
+---------------+--------------+-------------------------------------------+
10 rows in set (0.00 sec)

主库的密码update为同一个值,庆幸这些值不会应用到从库。此时查看复制正常,使用旧密码连接主库也正常

mydba@192.168.85.133,3306 [(none)]> pager cat | egrep 'Master_Log_File|Relay_Master_Log_File|Read_Master_Log_Pos|Exec_Master_Log_Pos|Running'
PAGER set to 'cat | egrep 'Master_Log_File|Relay_Master_Log_File|Read_Master_Log_Pos|Exec_Master_Log_Pos|Running''
mydba@192.168.85.133,3306 [(none)]> show slave status\G
Master_Log_File: mysql-bin.000108
Read_Master_Log_Pos: 3849
Relay_Master_Log_File: mysql-bin.000108
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Exec_Master_Log_Pos: 3849
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
1 row in set (0.00 sec) # 使用旧密码也还可以登录
C:\Users\Administrator>mysql -h192.168.85.132 -P3306 -umydba -p
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 5.7.19-log MySQL Community Server (GPL)

2.3、binlog

grant+update语句在主库的binlog

[root@ZST1 logs]# mysqlbinlog -v --base64-output=decode-rows mysql-bin. |more
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at
# :: server id end_log_pos CRC32 0x4861f6e9 Start: binlog v , server v 5.7.-log created ::
# Warning: this binlog is either in use or was not closed properly.
# at
# :: server id end_log_pos CRC32 0x4bf5e123 Previous-GTIDs
# 8ab82362-9c37-11e7-a858-000c29c1025c:-
# at
==================== GRANT操作对应的日志Start ====================
# :: server id end_log_pos CRC32 0x965501a5 GTID last_committed= sequence_number= rbr_only=no
SET @@SESSION.GTID_NEXT= '8ab82362-9c37-11e7-a858-000c29c1025c:69348'/*!*/;
# at
# :: server id end_log_pos CRC32 0xce77ebc8 Query thread_id= exec_time= error_code=
use `replcrash`/*!*/;
SET TIMESTAMP=/*!*/;
SET @@session.pseudo_thread_id=/*!*/;
SET @@session.foreign_key_checks=, @@session.sql_auto_is_null=, @@session.unique_checks=, @@session.autocommit=/*!*/;
SET @@session.sql_mode=/*!*/;
SET @@session.auto_increment_increment=, @@session.auto_increment_offset=/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=,@@session.collation_connection=,@@session.collation_server=/*!*/;
SET @@session.lc_time_names=/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
GRANT SELECT ON `sakila`.* TO 'test'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*0CB5F227B3E98395CA0C6F1427427E77ADF49F89'
/*!*/;
==================== GRANT操作对应的日志End ====================
# at
==================== UPDATE操作对应的日志Start ====================
# :: server id end_log_pos CRC32 0xaa76365b GTID last_committed= sequence_number= rbr_only=yes
/*!50718 SET TRANSACTION ISOLATION LEVEL READ COMMITTED*//*!*/;
SET @@SESSION.GTID_NEXT= '8ab82362-9c37-11e7-a858-000c29c1025c:69349'/*!*/;
# at
# :: server id end_log_pos CRC32 0x42f7046b Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
BEGIN
/*!*/;
# at
# :: server id end_log_pos CRC32 0x2f85fb49 Table_map: `mysql`.`user` mapped to number
# at
# :: server id end_log_pos CRC32 0xadc9af46 Update_rows: table id flags: STMT_END_F
### UPDATE `mysql`.`user`
### WHERE
### @='localhost'
### @='root'
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=''
### @=''
### @=''
### @=
### @=
### @=
### @=
### @='mysql_native_password'
### @='*A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5'
### @=
### @=
### @=NULL
### @=
### SET
### @='localhost'
### @='root'
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=''
### @=''
### @=''
### @=
### @=
### @=
### @=
### @='mysql_native_password'
### @='*A4B6157319038724E3560894F7F932C8886EBFCF'
### @=
### @=
### @=NULL
### @=
...
### UPDATE `mysql`.`user`
### WHERE
### @='%'
### @='test'
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=''
### @=''
### @=''
### @=
### @=
### @=
### @=
### @='mysql_native_password'
### @='*0CB5F227B3E98395CA0C6F1427427E77ADF49F89'
### @=
### @=
### @=NULL
### @=
### SET
### @='%'
### @='test'
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=
### @=''
### @=''
### @=''
### @=
### @=
### @=
### @=
### @='mysql_native_password'
### @='*A4B6157319038724E3560894F7F932C8886EBFCF'
### @=
### @=
### @=NULL
### @=
# at
# :: server id end_log_pos CRC32 0x752ce098 Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
COMMIT
/*!*/;
==================== UPDATE操作对应的日志End ====================
# at
# :: server id end_log_pos CRC32 0x7d007885 Rotate to mysql-bin. pos:
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@ZST1 logs]#

grant+update语句在从库的binlog

[root@ZST2 logs]# mysqlbinlog -v --base64-output=decode-rows mysql-bin. |more
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at
# :: server id end_log_pos CRC32 0x97380513 Start: binlog v , server v 5.7.-log created ::
# Warning: this binlog is either in use or was not closed properly.
# at
# :: server id end_log_pos CRC32 0x0e28801c Previous-GTIDs
# 8ab82362-9c37-11e7-a858-000c29c1025c:-,
# 93f69708-9c39-11e7-b7f8-000c2900c99c:-
# at
==================== 本地GRANT操作对应的日志Start(误操作) ====================
# :: server id end_log_pos CRC32 0x237b657c GTID last_committed= sequence_number= rbr_only=no
SET @@SESSION.GTID_NEXT= '93f69708-9c39-11e7-b7f8-000c2900c99c:285'/*!*/;
# at
# :: server id end_log_pos CRC32 0xf6511861 Query thread_id= exec_time= error_code=
use `replcrash`/*!*/;
SET TIMESTAMP=/*!*/;
SET @@session.pseudo_thread_id=/*!*/;
SET @@session.foreign_key_checks=, @@session.sql_auto_is_null=, @@session.unique_checks=, @@session.autocommit=/*!*/;
SET @@session.sql_mode=/*!*/;
SET @@session.auto_increment_increment=, @@session.auto_increment_offset=/*!*/;
/*!\C utf8 *//*!*/;
SET @@session.character_set_client=,@@session.collation_connection=,@@session.collation_server=/*!*/;
SET @@session.lc_time_names=/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
GRANT SELECT ON `sakila`.* TO 'test'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*0CB5F227B3E98395CA0C6F1427427E77ADF49F89'
/*!*/;
# at
# :: server id end_log_pos CRC32 0x9631a777 GTID last_committed= sequence_number= rbr_only=no
SET @@SESSION.GTID_NEXT= '93f69708-9c39-11e7-b7f8-000c2900c99c:286'/*!*/;
# at
# :: server id end_log_pos CRC32 0xd826df1b Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
drop user test@'%'
/*!*/;
==================== 本地GRANT操作对应的日志End(误操作) ====================
# at
==================== 复制GRANT操作对应的日志Start ====================
# :: server id end_log_pos CRC32 0xa645c110 GTID last_committed= sequence_number= rbr_only=no
SET @@SESSION.GTID_NEXT= '8ab82362-9c37-11e7-a858-000c29c1025c:69348'/*!*/;
# at
# :: server id end_log_pos CRC32 0x4924dc5a Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
GRANT SELECT ON `sakila`.* TO 'test'@'%' IDENTIFIED WITH 'mysql_native_password' AS '*0CB5F227B3E98395CA0C6F1427427E77ADF49F89'
/*!*/;
==================== 复制GRANT操作对应的日志End ====================
# at
==================== 复制UPDATE操作对应的日志Start ====================
# :: server id end_log_pos CRC32 0xab7a1a57 GTID last_committed= sequence_number= rbr_only=no
SET @@SESSION.GTID_NEXT= '8ab82362-9c37-11e7-a858-000c29c1025c:69349'/*!*/;
# at
# :: server id end_log_pos CRC32 0x40d16e6e Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
BEGIN
/*!*/;
# at
# :: server id end_log_pos CRC32 0x464fab8c Query thread_id= exec_time= error_code=
SET TIMESTAMP=/*!*/;
COMMIT
/*!*/;
==================== 复制UPDATE操作对应的日志End ====================
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
[root@ZST2 logs]#

当前环境下,主库上的binlog等效于从库上的relay-log,在主库的binlog中我们看到grant语句前面有use `replcrash`;从库在应用此relay-log时,不会过滤其后面的DDL/DCL语句,所以grant语句应用到从库,从库的binlog也看到对应记录,间接表明从库应用了grant语句。
主库的binlog中的UPDATE `mysql`.`user`语句影响的数据在mysql库下,从库应用此relay-log时,会过滤这些语句,所在update不会应用到从库,从库的binlog可以看到GTID_NEXT= '8ab82362-9c37-11e7-a858-000c29c1025c:69349'是一个空事务(BEGIN;COMMIT)

三、如何修复mysql.user

前面的update语句把主库的mysql.user密码更新错了,怎么还原到更新前的值?我自己的环境本身主、从mysql库是保持一致的,而且设置了复制过滤,update操作不会应用到从库,因此可以借助从库来修复主库的mysql.user

3.1、利用select into outfile + awk

# 数据导入导出限制目录
mydba@192.168.85.133, [replcrash]> show variables like 'secure_file_priv';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| secure_file_priv | /tmp/ |
+------------------+-------+
row in set (0.03 sec)
# 导出数据
mydba@192.168.85.133, [replcrash]> select user,host,authentication_string from mysql.user into outfile '/tmp/mysql_user.sql';
Query OK, rows affected (0.00 sec)
# 生成rollback语句(注意单引号)
[root@ZST2 logs]# cat /tmp/mysql_user.sql |awk '{print "update mysql.user set authentication_string='\''"$3"'\'' where user='\''"$1"'\'' and host='\''"$2"'\'';"}' >/tmp/roll_mysql_user.sql
[root@ZST2 logs]# cat /tmp/roll_mysql_user.sql
update mysql.user set authentication_string='*A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5' where user='root' and host='localhost';
update mysql.user set authentication_string='*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE' where user='mysql.session' and host='localhost';
update mysql.user set authentication_string='*THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE' where user='mysql.sys' and host='localhost';
update mysql.user set authentication_string='*A424E797037BF97C19A2E88CF7891C5C2038C039' where user='repl' and host='192.168.85.%';
update mysql.user set authentication_string='*A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5' where user='mydba' and host='192.168.85.%';
update mysql.user set authentication_string='*4E832DC6A6F24719A68C1242068114AA77CA60D0' where user='zst' and host='localhost';
update mysql.user set authentication_string='*A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5' where user='resolve' and host='db%.zst.com';
update mysql.user set authentication_string='*A7E26519238B6EA2F943D5FAC3CD7812AD8F87E5' where user='restoree' and host='192.168.85.%';
update mysql.user set authentication_string='*1975D095AC033CAF4E1BF94F7202A9BBFEEB66F1' where user='monitor' and host='%';
update mysql.user set authentication_string='*0CB5F227B3E98395CA0C6F1427427E77ADF49F89' where user='test' and host='%';
[root@ZST2 logs]#

将生成的脚本roll_mysql_user.sql应用到主库即可

3.2、MyISAM文件拷贝

# 拷贝文件
[root@ZST2 logs]# ll /data/mysql/mysql3306/data/mysql/user.*
-rw-r-----. mysql mysql Oct : /data/mysql/mysql3306/data/mysql/user.frm
-rw-r-----. mysql mysql Nov : /data/mysql/mysql3306/data/mysql/user.MYD
-rw-r-----. mysql mysql Nov : /data/mysql/mysql3306/data/mysql/user.MYI
[root@ZST2 logs]# scp /data/mysql/mysql3306/data/mysql/user.* root@192.168.85.132:/data/mysql/mysql3306/data/mysql/ # 注意检查拷贝过去的文件chown
# kill -HUP
[root@ZST1 ~]# kill -HUP `pidof mysqld`

借助MyISAM引擎特性,注意修改文件属主信息

3.3、binlog2sql

解析主库上的binlog得到要闪回的位置,利用binlog2sql得到操作前的记录

[root@ZST1 ~]# cd /tools/binlog2sql/binlog2sql
[root@ZST1 binlog2sql]# python binlog2sql.py --flashback -h192.168.85. -P3306 -umydba -p'mysql5719' -dmysql -tuser --start-file='mysql-bin.000108' --start-position= --stop-position=

mysql.user字段较多,update以ROW格式记录在binlog中,生成的闪回语句较长~

四、总结及疑问

4.1、总结

开篇问题的原因是,提问者在Master1、Master2没有指定default database的情况下创建了同名用户,在从库设置复制过滤后启动复制,Master1、Master2上的create user语句都应用到从库,导致第二次create user failed. 因此在操作DDL/DCL时记得USE DBNAME;

4.2、疑问

• update权限表,在什么时候生效?
内存结构中的权限信息何时被更新:FLUSH PRIVILEGES会强行让MySQL更新Load到内存中的权限信息;GRANT、REVOKE或者CREATE USER和DROP USER操作会直接更新内存中的权限信息;重启MySQL会让MySQL完全从grant tables中读取权限信息。
内存结构中的权限信息更新之后对已经连接上的用户何时生效:对于Global Level的权限信息的修改,仅仅只有更改之后新建连接才会用到,已经连接上的session并不会受到影响。对于Database Level的权限信息的修改,只有当客户端请求执行了“use database_name”命令之后,才会在重新校验中使用到新的权限信息。对于Table Level和Column Level的权限,在下一次需要使用到该权限的Query被请求的时候生效。
本例中update mysql.user是属于Global Level,只有在FLUSH PRIVILEGES后,新建连接才会要求使用新密码,当前已连接上的session不受影响。
• 系统库(information_schema、performance_schema、sys)会复制吗?
• 多源复制Master存在同名数据库,会出现什么情况?
对于同名数据库,Slave上的数据会错乱,因为Master1、Master2对同名数据库的变更全部会应用到Slave,一旦它们操作相同对象,就会出现交错。

多源复制遇到CREATE USER FAILED错误的更多相关文章

  1. mysql5.7 安装和多源复制实践

    MySQL 5.7发布后,在复制方面有了很大的改进和提升.比如开始支持多源复制(multi-source)以及真正的支持多线程复制了.多源复制可以使用基于二进制日子的复制或者基于事务的复制.下面我们说 ...

  2. MySQL多源复制(八)

    一.什么是多源复制 MySQL 5.7发布后,在复制方面有了很大的改进和提升.比如开始支持多源复制(multi-source)以及真正的支持多线程复制了.多源复制可以使用基于二进制日志的复制或者基于事 ...

  3. MySQL多源复制

    MySQL多源复制 1. 配置多源复制 1.1 配置环境如下 1.2 从库的重要参数配置 1.3 在Master上导出需要同步的数据库 1.4 在master上创建复制账号 1.5 备份数据导入 1. ...

  4. MariaDB的GTID复制和多源复制

    什么是GTID? GTID就是全局事务ID(global transaction identifier ),最初由google实现,官方MySQL在5.6才加入该功能.GTID实际上是由UUID+TI ...

  5. ORA-01501: CREATE DATABASE failed

    使用dbca建库时遇到ORA-01501: CREATE DATABASE failed这个错误,检查告警日志,发现有下面错误信息: SMON: enabling tx recovery Fri Ap ...

  6. MySql5.7-多源复制(多主单从)

    1.1.主库配置 my.cnf   #确保唯一 server-id=1 #作为Master要开启binlog log-bin=mysql-bin #binlog format有三种形式:Stateme ...

  7. linux svn authorization failed错误

    authorization failed错误主要是conf/auth文件配置错误,可以参考如下配置: [aliases] # joe = /C=XZ/ST=Dessert/L=Snake City/O ...

  8. MariaDB多源复制环境搭建(多主一丛)

    环境: 192.168.1.248 HE1 主库 192.168.1.249 HE2 主库 192.168.1.250 HE3 从库 主库授权备份账户 mysql>  grant SELECT, ...

  9. 用winscp从本地上传文件到服务器上出现复制文件到远端时错误。

    用winscp从本地上传文件到服务器上出现复制文件到远端时错误. 错误码:4 服务器返回的错误消息:write failed 报错如下图所示: 分析过程: 1.刚开始以为是权限不够,后面上网查了一下是 ...

随机推荐

  1. imagick用法!

    https://coderwall.com/p/9hj97w sudo apt-get install imagemagick sudo apt-get install php5-imagick su ...

  2. js页面实时显示时间

    1.通过getMonth()实现获取月份,从0开始计数,需要+1: 2.通过getDay()实现获取星期天数,从0开始,0表示星期日: 3.通过getDate()获取日期. 4.setTimeout( ...

  3. Beta版本冲刺(三)

    目录 组员情况 组员1(组长):胡绪佩 组员2:胡青元 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示 ...

  4. Beta阶段冲刺四

    Beta阶段冲刺四 Task1:团队TSP 团队任务 预估时间 实际时间 完成日期 新增其他学院的爬虫 180 130 11.30 新增其他学院的数据库字段修改 180 160 12.1 新增其他学院 ...

  5. 第九周PSP&进度条

    PSP 一.表格: D日期     C类型 C内容 S开始时间 E结束时间 I时间间隔 T净时间(mins) 预计花费时间(mins) 11月11号 讨论 讨论beta发布 09:00 09:54 1 ...

  6. 如何自定义微信小程序swiper轮播图面板指示点的样式

    https://www.cnblogs.com/myboogle/p/6278163.html 微信小程序的swiper组件是滑块视图容器,也就是说平常我们看到的轮播图就可以用它来做,不过这个组件有很 ...

  7. OneZero第五周第一次站立会议(2016.4.18)

    1. 时间: 13:00--13:15  共计15分钟. 2. 成员: X 夏一鸣 * 组长 (博客:http://www.cnblogs.com/xiaym896/), G 郭又铭 (博客:http ...

  8. appium获取Toast内容的方法

    做自动化测试的时候,可能需要根据弹出的Toast提示来做下一步判断.这里记录一下获取Toast内容的方法,同时巩固一下显示等待的方法之一WebDriverWait. from selenium.web ...

  9. Java之数据流-复制二进制文件

    package test_demo.fileoper; import java.io.*; /* * 数值字节流操作,复制二进制文件 * 输入流:从文件中读取数据,扩展为数据流(二进制) * 输出流: ...

  10. bzoj 4448 [Scoi2015]情报传递 (树链剖分+主席树)

    题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=4448 题面: Description 奈特公司是一个巨大的情报公司,它有着庞大的情报网络 ...