【引言】
大家都知道,MySQL配置了同步,通用账号密码在master做了修改,slave会自动同步过来。但有一个账号除外,那就是同步账号。
是不是第一感觉不太对?
为啥主从配置下的其他账号密码的修改都能同步,即使是root@local这样的本地账号都能同步至从库,同步账号就不行?
大家都知道,MySQL账号信息是保存在数据字典mysql.user中,按照道理来说,mysql.user内容的修改是会同步至从库。
先看一段在配置同步过程中change master的一段官方介绍:
MySQL 5.6官方介绍, 链接:
https://dev.mysql.com/doc/refman/5.6/en/change-master-to.html
CHANGE MASTER TO changes the parameters that the replica uses for connecting to the replication source server, for reading the source's binary log, and reading the replica's relay log. It also updates the contents of the replication metadata repositories (see Section 17.2.2, “Relay Log and Replication Metadata Repositories”). CHANGE MASTER TO requires the SUPER privilege.
In MySQL 5.6.11 and later,gtid_next must also be set to AUTOMATIC (Bug #16062608).
看到这里应该明白了,这里以配置了gtid的同步配置为例
change master to
master_host='192.168.0.110',
master_user='replication_account',
master_password='user_password',
master_port=3306,
master_auto_position=1;
按照上述MySQL官方文档解释,从库通过CHANGE MASTER TO 中的上述参数来做三件事:连接主库、读取主库binary log,读取从库relay log。
可以得出原因说明:
当主库master的同步账号发成改变,从库中的change master to中的同步账号配置在第一个阶段connecting master server时,会连接不通,原因为change master to 的相关配置是存放在从库的复制元数据存储库(replication metadata repositories)中,而复制元数据存储库这时还是保存的原来的同步账号密码。
所以,主库修改了同步账号,从库需要做一次updates the contents of the replication metadata repositories,才能保证从库对主库的连接成功,Slave_IO_Running才会由 connecting状态变为yes正常状态。
那如何修改同步账号呐?
再接着看官方文档,链接:
https://dev.mysql.com/doc/refman/5.6/en/change-master-to.html
Options not specified retain their value, except as indicated in the following discussion. Thus, in most cases, there is no need to specify options that do not change. For example, if the password to connect to your MySQL source has changed, issue these statements to tell the replica about the new password:
STOP SLAVE; -- if replication was running
CHANGE MASTER TO MASTER_PASSWORD='new3cret';