master:192.168.100.1
slave:192.168.100.2
1、根据《CentOS7安装mysql5.7(1)—配置master节点》安装好slave节点,my.cnf中server-id=2
注意将mysqldb01改成mysqldb02
2、master节点配置my.cnf
server-id=1
log-bin=mysql-bin
binlog-format = Row
binlog_cache_size = 4M
max_binlog_size = 256M
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
expire_logs_days=30
slave-net-timeout=60
3、master节点重启mysql
systemctl restart mysqld
4、master节点建立复制账户
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> CREATE USER 'repl'@'%' IDENTIFIED BY 'Xxl#20xx12';
Query OK, 0 rows affected (0.00 sec)
mysql> grant replication slave on *.* to 'repl'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
5、查询master节点状态
mysql> show master status\G;
*************************** 1. row ***************************
File: mysql-bin.000003
Position: 747
Binlog_Do_DB:
Binlog_Ignore_DB: information_schema,mysql,performance_schema,sys
Executed_Gtid_Set:
1 row in set (0.00 sec)
6、slave节点配置my.cnf
server-id=2
log-bin=mysql-bin
binlog-format = Row
binlog_cache_size = 4M
max_binlog_size = 256M
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
log-slave-updates
expire_logs_days=30
slave-net-timeout=60
relay-log=mysqldb02-relay-bin
master-info-repository=table
relay-log-info-repository=table
7、slave节点重启mysql
systemctl restart mysqld
8、slave节点建立复制账户
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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> CREATE USER 'repl'@'%' IDENTIFIED BY 'Xxl#20xx12';
Query OK, 0 rows affected (0.01 sec)
mysql> grant replication slave on *.* to 'repl'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
9、配置slave连接master
mysql> change master to master_host='192.168.100.1',master_port=3310,master_user='repl',master_password='Xxl#20xx12',master_log_file='mysql-bin.000003',master_log_pos=747 for channel 'c1';
Query OK, 0 rows affected, 2 warnings (0.10 sec)
mysql> start slave for channel 'c1';
Query OK, 0 rows affected (0.01 sec)
其中master_log_file,master_log_pos从master节点状态中获得
10、查看slave节点状态
mysql> show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.100.1
Master_User: repl
Master_Port: 3310
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 747
Relay_Log_File: mysqldb02-relay-bin-c1.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 747
Relay_Log_Space: 534
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID: 1606b628-f33b-11eb-a4b5-00163cd5cd1b
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name: c1
Master_TLS_Version:
1 row in set (0.00 sec)
其中最重要的状态:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates