Your MySQL connection> Server version: 5.7.18-log Source distribution
Copyright (c) 2000, 2017, 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> grant replication slave, replication client on *.* to 'repl'@'192.168.1.253'> mysql> flush privileges;
Query OK, 0 rows affected (0.06 sec)
5、在node1上查看并记录binlog文件的position和File的值,配置从机时会用到
mysql> show master status;
+-----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------------+----------+--------------+------------------+-------------------+
| lamp-mysql-bin.000001 | 631 | | mysql | |
+-----------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
6、在node2上将node1作为自己的主服务器,并且开启slave状态。
mysql> change master to master_host='192.168.1.254',master_user='repl', master_password='repl@123', master_port=3306, master_log_file='lamp-mysql-bin.000001', master_log_pos=631, master_connect_retry=30;
mysql> start slave;
7、在node2上查看自己的slave状态。
mysql> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
以上两个参数要全部是Yes状态
8、在node2上创建允许从node1同步的账号
[root@node2 ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection> Server version: 5.7.18-log Source distribution
Copyright (c) 2000, 2017, 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> grant replication slave, replication client on *.* to 'repl'@'192.168.1.254'> mysql> flush privileges;
9、在node2上查看并记录binlog文件的position和File的值。
mysql> show master status;
+-----------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------------+----------+--------------+------------------+-------------------+
| lamp-mysql-bin.000001 | 474 | | mysql | |
+-----------------------+----------+--------------+------------------+-------------------+
10、在node1上将node2作为自己的主服务器,并且开启slave状态。
mysql> change master to master_host='192.168.1.253',master_user='repl', master_password='repl@123', master_port=3306, master_log_file='lamp-mysql-bin.000001', master_log_pos=474, master_connect_retry=30;
mysql> start slave;
11、在node1上查看自己的slave状态。
mysql> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
以上两个参数要全部是Yes状态
12、在node1或node2任意一台数据库中创建数据库,会自动同步到另外一台数据库
mysql> create database netser;
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| netser |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.09 sec)
在另外一个节点,查看数据库,会看到完全一致的数据信息
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| netser |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.06 sec)