[root@localhost mysql]# cat my.cnf
[mysqld]
log-bin=/var/log/mysql/mysql-bin
server-id=1
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
port=3306
mkdir /var/log/mysql
chown -R mysql:mysql /var/log/mysql
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
1 row in set (0.02 sec)
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show variables like '%skip_networking%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| skip_networking | OFF |
+-----------------+-------+
1 row in set (0.00 sec)
mysql>
mysql> CREATE USER 'rep1'@'%';
mysql> GRANT REPLICATION SLAVE ON *.* TO 'rep1'@'%' identified by 'coolsummermoon';
mysql> show master status\G
*************************** 1. row ***************************
File: mysql-bin.000003
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
mysql>
[root@localhost mysql]# mysql -u rep1 -h 192.168.0.66 -P 3306 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1036
Server version: 5.7.21-log MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
[root@localhost mysql]# cat my.cnf
[mysqld]
server-id=2
port=3306
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
1 row in set (0.01 sec)
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | OFF |
+---------------+-------+
1 row in set (0.01 sec)
mysql>
mysql> CHANGE MASTER TO MASTER_HOST='192.168.0.66',MASTER_USER='rep1',MASTER_PASSWORD='coolsummermoon',MASTER_LOG_FILE='mysql-bin.000003',MASTER_LOG_POS=154;
mysql> start slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.66
Master_User: rep1
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000003
Read_Master_Log_Pos: 1566853
Relay_Log_File: localhost-relay-bin.000002
Relay_Log_Pos: 1567019
Relay_Master_Log_File: mysql-bin.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
mysql> stop slave;
mysql> reset slave all;
主上创建数据库插入数据等操作,从上能同步即可