设置主 - 从复制:连接到主时出错(错误代码:2003)

TH1*_*981 5 mysql replication

我在两个不同的托管公司的两个不同的服务器上配置它。

这是我遵循的设置教程:https : //www.digitalocean.com/community/tutorials/how-to-set-up-master-slave-replication-in-mysql

高手my.cnf设置如下:

bind-address = 00.000.000.00
server-id = 1
log_bin = /var/log/mysql/mysql-bin.log
binlog_do_db = mydatabase
Run Code Online (Sandbox Code Playgroud)

在奴隶上:

server-id = 2
relay-log = /var/log/mysql/mysql-relay-bin.log
expire_logs_days = 10
max_binlog_size = 100M
binlog_do_db = mydatabase
Run Code Online (Sandbox Code Playgroud)

一切看起来都不错,直到我尝试检查 mysql> SHOW SLAVE STATUS\G

*************************** 1. row ***************************
Slave_IO_State: Connecting to master
Master_Host: 000.000.000.00
Master_User: slave_user
Master_Port: 3306
Connect_Retry: 60
Master_Log_File:
Read_Master_Log_Pos: 4
Relay_Log_File: mysql-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File:
Slave_IO_Running: Connecting
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: 0
Relay_Log_Space: 154
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: 2003
Last_IO_Error: error connecting to master 'slave_user@000.000.000.00' - retry-time: 60  retries: 3
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: /var/lib/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: 180104 23:22:36
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:
Run Code Online (Sandbox Code Playgroud)

我也检查了错误日志,可以看到:

2018-01-04T23:05:10.948738Z 2 [ERROR] Slave I/O for channel '': error connecting to master 'slave_user@000.000.000.00:3306' - retry-time: 60  retries: 6, Error_code: 2003
Run Code Online (Sandbox Code Playgroud)

我检查了防火墙和端口,看起来是正确的。我不确定我还能检查什么?

TH1*_*981 7

所以,我实际上有几个问题可能会派上用场,供其他人解决:

错误:2003

bind-address从主人那里删除了

错误:1045

用户访问被拒绝

我为从属用户明确设置了 IP 地址:

GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'000.000.000.00' IDENTIFIED BY 'password';

代替

GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'password';

错误 1236

从二进制日志读取数据时,从主服务器收到致命错误 1236:'日志事件条目超出 max_allowed_pa​​cket

事实证明max_allowed_packet,<= 5.6.5的默认值为 1MB,>= 5.6.6的默认值为 4MB。

我按照本文将这两个手动设置为 16MB

错误 1236

从二进制日志读取数据时,从主服务器收到致命错误 1236:'日志事件中的虚假数据

我按照此答案中的说明进行操作

这解决了我的最后一个错误,现在复制似乎按预期工作了!