root@d1e4a1eb0bed:/# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands endwith;or \g. Your MySQL connection id is6 Server version: 5.7.28 MySQL Community Server (GPL)Copyright (c)2000,2019, Oracle and/or its affiliates.All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type'help;'or'\h'for help.Type'\c'to clear the current input statement.mysql> mysql>CREATEUSER'slave'@'%' IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.01 sec)mysql> GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'slave'@'%'; Query OK,0rows affected (0.00 sec)
查询 master 的 master_log_pos,这里查到的 Position 在后面配置slave的时候要用,
root@d8a4501c94b7:/# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands endwith;or \g. Your MySQL connection id is3 Server version: 5.7.28-log MySQL Community Server (GPL)Copyright (c)2000,2019, Oracle and/or its affiliates.All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type'help;'or'\h'for help.Type'\c'to clear the current input statement.mysql> change master to master_host='172.17.0.2', master_user='slave', master_password='123456', master_port=3306, master_log_file='mysql-bin.000001', master_log_pos=2830, master_connect_retry=30; Query OK,0rows affected,2warnings(0.08 sec)start slave;--- 注意这里启动slaveshow slave status\G;
状态查询:show global variables like “%read_only%”;
show global variables like "%read_only%"; 查询只读状态,如果set global read_only=1;, 则read_only为ON, set global read_only=0; read_only 为OFF