问题描述
这个问题跟着我之前(未解决)的问题:MySQL master-slave replication connection failure
我决定在https://dev.mysql.com/doc/refman/5.7/en/replication-configuration.html之后设置最简单的复制。这个想法是使所有工作正常,然后逐步更改为所需的设置。悬崖注释版本:发生1236错误。该问题的末尾列出了为什么1236错误的常见来源似乎不适用。
主服务器是MysqL 5.7.32,仅由我用于此复制测试。复制数据库是testdb
,其中testdb
是最简单的。它不包含表或数据。当testdb
包含一个具有5行的简单表时,每行包含2个简短的VARCHAR和2个INT。
Replica是MysqL 8.0。
复制用户:repl_user
对master
的repl_user权限:
MysqL> select host,user,Repl_slave_priv,Repl_client_priv from MysqL.user where user='repl_user';
+---------------------------------+-----------+-----------------+------------------+
| host | user | Repl_slave_priv | Repl_client_priv |
+---------------------------------+-----------+-----------------+------------------+
| 127.0.0.1 | repl_user | Y | N |
| localhost | repl_user | Y | N |
| % | repl_user | Y | N |
| slave_ip | repl_user | Y | N |
+---------------------------------+-----------+-----------------+------------------+
>MysqL -u repl_user -h master_ip -p -P 3306
Welcome to the MysqL monitor. Commands end with ; or \g.
Your MysqL connection id is 15
Server version: 5.7.32-log MysqL Community Server (GPL)
MysqLdump -u root -p --databases testdb --master-data > master_testdb_dump20201110.sql
将其插入副本中:
MysqL -u root -p < master_testdb_dump20201110.sql
在母版上:
MysqL> SHOW MASTER STATUS;
+-------------------+----------+--------------+------------------+-------------------+
| File | Position | binlog_Do_DB | binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| MysqLd-bin.000002 | 488 | | | |
+-------------------+----------+--------------+------------------+-------------------+
MysqL> SHOW BINARY LOGS;
+-------------------+-----------+
| Log_name | File_size |
+-------------------+-----------+
| MysqLd-bin.000001 | 177 |
| MysqLd-bin.000002 | 488 |
+-------------------+-----------+
2 rows in set (0.00 sec)
在副本上:
CHANGE MASTER TO MASTER_HOST='master_ip',MASTER_USER='repl_user',MASTER_PASSWORD='correct password',MASTER_LOG_FILE='MysqL-bin.000002',MASTER_LOG_POS=488,master_port=3306;
Query OK,0 rows affected,2 warnings (0.01 sec)
start replica;
show replica status\G
*************************** 1. row ***************************
Replica_IO_State:
Source_Host: host_ip
Source_User: repl_user
Source_Port: 3306
Connect_Retry: 60
Source_Log_File: MysqL-bin.000002
Read_Source_Log_Pos: 488
Relay_Log_File: replica_name-relay-bin.000001
Relay_Log_Pos: 4
Relay_Source_Log_File: MysqL-bin.000002
Replica_IO_Running: No
Replica_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_Source_Log_Pos: 488
Relay_Log_Space: 156
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Source_SSL_Allowed: No
Source_SSL_CA_File:
Source_SSL_CA_Path:
Source_SSL_Cert:
Source_SSL_Cipher:
Source_SSL_Key:
Seconds_Behind_Source: NULL
Source_SSL_Verify_Server_Cert: No
Last_IO_Errno: 13114
Last_IO_Error: Got Fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
Last_sql_Errno: 0
Last_sql_Error:
Replicate_Ignore_Server_Ids:
Source_Server_Id: 4
Source_UUID: e4e01e90-1e22-11eb-84b1-0015175ac510
Source_Info_File: MysqL.slave_master_info
sql_Delay: 0
sql_Remaining_Delay: NULL
Replica_sql_Running_State: Slave has read all relay log; waiting for more updates
Source_Retry_Count: 86400
Source_Bind:
Last_IO_Error_Timestamp: 201110 07:53:50
Last_sql_Error_Timestamp:
Source_SSL_Crl:
Source_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Source_TLS_Version:
Source_public_key_path:
Get_Source_public_key: 0
Network_Namespace:
1 row in set (0.00 sec)
Relay_Log_File确实存在于副本上,并且是一个非空的二进制文件。
我在主副本和副本副本上的/var/log/MysqL/MysqL.log上都做了一个尾-f:
复制日志:
2020-11-10T15:58:04.075427Z 11 Query CHANGE MASTER TO MASTER_HOST = 'master_ip',MASTER_USER = 'repl_user',MASTER_PASSWORD = <secret>,MASTER_PORT = 3306,MASTER_LOG_FILE = 'MysqL-bin.000002',MASTER_LOG_POS = 488
2020-11-10T15:58:07.411303Z 11 Query start replica
2020-11-10T15:58:07.413325Z 12 Connect Out repl_user@master_ip:3306
2020-11-10T15:58:10.750305Z 11 Query show replica status
主日志:
2020-11-10T15:58:07.413034Z 20 Connect repl_user@replica_ip on using TCP/IP
2020-11-10T15:58:07.413483Z 20 Query SELECT UNIX_TIMESTAMP()
2020-11-10T15:58:07.413744Z 20 Query SELECT @@GLOBAL.SERVER_ID
2020-11-10T15:58:07.413935Z 20 Query SET @master_heartbeat_period= 30000001024
2020-11-10T15:58:07.414132Z 20 Query SET @master_binlog_checksum= @@global.binlog_checksum
2020-11-10T15:58:07.414321Z 20 Query SELECT @master_binlog_checksum
2020-11-10T15:58:07.414529Z 20 Query SELECT @@GLOBAL.GTID_MODE
2020-11-10T15:58:07.414731Z 20 Query SELECT @@GLOBAL.SERVER_UUID
2020-11-10T15:58:07.414917Z 20 Query SET @slave_uuid= 'a1932c42-9d74-11e7-ba23-0015175696ac'
2020-11-10T15:58:07.415394Z 20 binlog Dump Log: 'MysqL-bin.000002' Pos: 488
2020-11-10T16:05:39.836945Z 14 Query select host,Repl_client_priv from MysqL.user where user='repl_user'
掌握my.cnf:
[MysqLd]
default_authentication_plugin=MysqL_native_password
datadir=/var/lib/MysqL
socket=/var/lib/MysqL/MysqL.sock
symbolic-links=0
general_log_file = /var/log/MysqL/MysqL.log
general_log = 1
server-id=4
log-bin=MysqLd-bin
bind-address=0.0.0.0
innodb_flush_log_at_trx_commit=1
sync_binlog=1
max_allowed_packet=64M
[MysqLd_safe]
log-error=/var/log/MysqLd.log
pid-file=/var/run/MysqLd/MysqLd.pid
user=MysqL
skip-slave-start
复制my.cnf:
[MysqLd]
default_authentication_plugin=MysqL_native_password
datadir=/var/lib/MysqL
socket=/var/lib/MysqL/MysqL.sock
symbolic-links=0
general_log_file = /var/log/MysqL/MysqL.log
general_log = 1
server-id=1
log-bin=MysqLd-bin
bind-address=0.0.0.0
innodb_flush_log_at_trx_commit=1
sync_binlog=1
max_allowed_packet=64M
skip-slave-start
[MysqLd_safe]
log-error=/var/log/MysqLd.log
pid-file=/var/run/MysqLd/MysqLd.pid
user=MysqL
解决可能的故障模式
@petergd指出https://www.percona.com/blog/2014/10/08/mysql-replication-got-fatal-error-1236-causes-and-cures/关于1236种可能的原因和解决方法。 (我也阅读了许多其他页面和MysqL文档;我花了几天时间进行这个简单的设置。)
-
max_allowed_packet
在主服务器和副本服务器上均进行了统一设置。默认值为64M,并且大大超过了最大行(因为没有数据行)。 -
“当从属服务器为复制所需的二进制日志不再存在于主数据库服务器上时,将发生此错误。”以上文章证明了二进制日志确实存在。我还通过发出
手动验证了MysqLd-bin.000002
ls /var/lib/MysqL
的存在 -
似乎缺少二进制文件。 my.cnf中未启用日志到期。
Source_Log_File
位于服务器上/var/lib/MysqL
目录中。Relay_Log_File
和Relay_Source_Log_File
存在于/var/lib/MysqL
目录中的副本上。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)