1.准备两台装好mysql的机器
我的两台主机分别为 10.20.4.58 和10.20.4.59
58为mater机器 59为slave机器
在msater上的mysql创建一个用户
mysql> grant replication slave on *.* to 'repl'@'10.20.4.59' identified by '{yourPassword}';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
{yourPassword} 自己设定的密码
2. 修改master(58)的my.cnf
server-id=58
log-bin=mysqlbin-log
binlog_format=mixed
read-only=0
binlog-ignore-db=information_schema
binlog-ignore-db=mysql
binlog-ignore-db=performance_schema
binlog-ignore-db=sys
auto_increment_increment=2
auto_increment_offset=1
重启mysql服务
3. 修改slave(59)的my.cnf
server-id=59
log-bin=mysqlbin-log
binlog_format=mixed
replicate-ignore-db=information_schema
replicate-ignore-db=mysql
replicate-ignore-db=performance_schema
replicate-ignore-db=sys
log-slave-updates=ON
重启mysql服务
4 . 查看master机器的状态,在mysql下运行
mysql> show master status\G
*************************** 1. row ***************************
File: mysqlbin-log.000003
Position: 1270
Binlog_Do_DB:
Binlog_Ignore_DB: information_schema,mysql,performance_schema,sys
Executed_Gtid_Set:
1 row in set (0.00 sec)
记住 Position和File
5. 在slave机器配置master的信息
mysql> CHANGE MASTER TO MASTER_HOST='10.20.4.58', MASTER_USER='repl', MASTER_PASSWORD='{yourPassword}', MASTER_LOG_FILE='mysqlbin-log.000003', MASTER_LOG_POS=1270;
Query OK, 0 rows affected, 2 warnings (0.02 sec)
查看slave状态,如果 Slave_IO_Running和 Slave_SQL_Running都为Yes,说明配置就是成功了。
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.20.4.58
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysqlbin-log.000004
Read_Master_Log_Pos: 1270
Relay_Log_File: microService59-relay-bin.000002
Relay_Log_Pos: 323
Relay_Master_Log_File: mysqlbin-log.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB: information_schema,mysql,performance_schema,sys
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: 154
Relay_Log_Space: 539
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: 58
Master_UUID: 24ab31cd-8738-11e8-8f03-000c290c1fa6
Master_Info_File: /data/mysql/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:
Master_TLS_Version:
1 row in set (0.00 sec)
6. 验证
在master上创建一个表,看是否能够正常同步到slave机器上。