1.1.1. If a crash happens thisconfiguration does not guarantee that the relay log info will be consistent
【环境描述】
msyql5.6.14
【报错信息】
mysql的slave启动时,error.log中出现Warning警告:
[Warning] Slave SQL: If a crash happensthis configuration does not guarantee that the relay log info will beconsistent, Error_code: 0
这条Warning信息对Mysql和MySQL复制功能没有任何影响。
【报错原因】
MySQL5.6版本开始支持把master.info和relay-log.info的内容写入到mysql库的表中,
master.info--> mysql.slave_master_info
relay-log.info--> mysql. slave_relay_log_info
同时在MySQL5.6版本中,增加了 Slave crash-safe replication功能,为了保证mysql的replication能够crash-safe,slave_master_info和slave_relay_log_info表必须使用事务型的存储引擎(InnoDB),不要尝试去手动修改这两张表的内容。同时,Slave还要开启relay_log_recovery功能。
【解决方法】
设置master_info_repository和relay_log_info_repository的值为TABLE,同时开启relay_log_recovery功能。
修改/etc/my.cnf配置文件,添加以下3项:
master-info-repository=table # 可以使用set global 动态修改
relay-log-info-repository=table # 可以使用setglobal 动态修改
relay-log-recovery=1 # 只读参数,必须修改my.cnf重启mysql
然后重启mysql实例。
【参考资料】
l master.info和relay-log.info日志
在复制的Slave节点上会创建两个日志,分别是master.infor和relay-log.info,位于datadir目录中。在MySQL5.6和后续的版本中,可以通过设置master-info-file和relay-log-info-file参数来指定写入到mysql的表中或者写入文件。
这两个文件中包含一些类似showslave status输出的信息,当slave启动的时候会读取master.info和relay-log.info文件来确定从master读取binary log和读取relay log的信息。
Slave的I/O线程负责更新维护master.info文件,
master.info
mysql.slave_master_info
SHOW SLAVE STATUS Column
Description
1
Number_of_lines
[None]
Number of lines in the file
2
Master_log_name
Master_Log_File
The name of the master binary log currently being read from the master
3
Master_log_pos
Read_Master_Log_Pos
The current position within the master binary log that have been read from the master
4
Host
Master_Host
The host name of the master
5
User
Master_User
The user name used to connect to the master
6
User_password
Password (not shown by SHOW SLAVE STATUS)
The password used to connect to the master
7
Port
Master_Port
The network port used to connect to the master
8
Connect_retry
Connect_Retry
The period (in seconds) that the slave will wait before trying to reconnect to the master
9
Enabled_ssl
Master_SSL_Allowed
Indicates whether the server supports SSL connections
10
Ssl_ca
Master_SSL_CA_File
The file used for the Certificate Authority (CA) certificate
11
Ssl_capath
Master_SSL_CA_Path
The path to the Certificate Authority (CA) certificates
12
Ssl_cert
Master_SSL_Cert
The name of the SSL certificate file
13
Ssl_cipher
Master_SSL_Cipher
The list of possible ciphers used in the handshake for the SSL connection
14
Ssl_key
Master_SSL_Key
The name of the SSL key file
15
Ssl_verify_server_cert
Master_SSL_Verify_Server_Cert
Whether to verify the server certificate
16
Heartbeat
[None]
Interval between replication heartbeats, in seconds
17
Bind
Master_Bind
Which of the slave's network interfaces should be used for connecting to the master
18
Ignored_server_ids
Replicate_Ignore_Server_Ids
The number of server IDs to be ignored, followed by the actual server IDs
19
Uuid
Master_UUID
The master's unique ID
20
Retry_count
Master_Retry_Count
Maximum number of reconnection attempts permitted Added in MySQL 5.6.1)
Slave的SQL线程负责维护relay-log.info文件,在MySQL5.6中relay-log.info包含文件中的记录数和复制延迟的秒数。
relaylog.info
slave_relay_log_info
显示从属状态
描述
1
Number_of_lines
[无]
文件中的行数或表中的行数
2
Relay_log_name
Relay_Log_File
当前中继日志文件的名称
3
Relay_log_pos
Relay_Log_Pos
中继日志文件中的当前位置;到此位置的事件已在从数据库上执行
4
Master_log_name
Relay_Master_Log_File
主二进制日志文件的名称,其中已读取中继日志文件中的事件
5
Master_log_pos
Exec_Master_Log_Pos
已读取事件在主服务器二进制日志文件中的等效位置已执行
6
Sql_delay
SQL_Delay
从站必须落后主站的秒数
设置master_info_repository和relay_log_info_repository参数:
SQL>停止从属;
SQL>设置全局 master_info_repository=table;
SQL>设置全局relay_log_info_repository=table;
SQL>;显示诸如 '%repository';
之类的变量 ------------------------------------ -- ---------
|变量名 |值 |
-------------------------------------- ---- -----
|主信息库 |表|
|中继日志信息存储库 |表 |
-------------------------------------- ---- ------
查看向Master读取日志的情况:
SQL> select * from Slave_master_info;
查看Slave的Relay日志应用情况:
SQL> select * from Slave_relay_log_info;
注意:
master.info和relay-log.info内的数据肯定会有延迟,依赖mysql把slave信息刷到硬盘的时间,如果要获取slave的实时信息,可以查询slave_master_info和slave_relay_log_info表,或者执行show Slave状态查看。
l master-info-repository
master-info-repository={ FILE | TABLE },默认值为FILE,这个参数用于设置Slave节点上把master的信息写入到物理文件中还是写入到mysql。
如果设置为FILE,也是mysql的默认设置,Slave会在datadir/master.info文件中记录master的信息,从MySQL5.6版本开始,建议使用TABLE模式。
l relay-log-info-reposity
relay-log-info-reposity=file|table,默认值为FILE,这个参数用于设置slave节点上把relay-log.info的信息写入到datadir/relay-log.info文件或者mysql。 Slave_relay_log_info表。
如果设置为FILE,也是mysql的默认设置,Slave会在datadir/master.info文件中记录master的信息,从MySQL5.6版本开始,建议使用TABLE模式。
l relay-log-recovery
relay-log-recover=0|1,默认值为0不开启,该参数用于设置是否开启relay log的自动恢复功能。当开启relay_log_recovery功能,slave数据库在启动的时候,会忽略同步执行的中继日志,它会重新连接master获取中继日志来进行恢复。
当slave发生宕机的时候,建议开启该功能,可以有效避免slave执行了relay log里面的讹误记录。
如果开启relay_log_recovery功能,必须同时把relay_log_info_reposity设置为TABLE模式。

ACID属性包括原子性、一致性、隔离性和持久性,是数据库设计的基石。1.原子性确保事务要么完全成功,要么完全失败。2.一致性保证数据库在事务前后保持一致状态。3.隔离性确保事务之间互不干扰。4.持久性确保事务提交后数据永久保存。

MySQL既是数据库管理系统(DBMS),也与编程语言紧密相关。1)作为DBMS,MySQL用于存储、组织和检索数据,优化索引可提高查询性能。2)通过SQL与编程语言结合,嵌入在如Python中,使用ORM工具如SQLAlchemy可简化操作。3)性能优化包括索引、查询、缓存、分库分表和事务管理。

MySQL使用SQL命令管理数据。1.基本命令包括SELECT、INSERT、UPDATE和DELETE。2.高级用法涉及JOIN、子查询和聚合函数。3.常见错误有语法、逻辑和性能问题。4.优化技巧包括使用索引、避免SELECT*和使用LIMIT。

MySQL是一种高效的关系型数据库管理系统,适用于存储和管理数据。其优势包括高性能查询、灵活的事务处理和丰富的数据类型。实际应用中,MySQL常用于电商平台、社交网络和内容管理系统,但需注意性能优化、数据安全和扩展性。

SQL和MySQL的关系是标准语言与具体实现的关系。1.SQL是用于管理和操作关系数据库的标准语言,允许进行数据的增、删、改、查。2.MySQL是一个具体的数据库管理系统,使用SQL作为其操作语言,并提供高效的数据存储和管理。

InnoDB使用redologs和undologs确保数据一致性和可靠性。1.redologs记录数据页修改,确保崩溃恢复和事务持久性。2.undologs记录数据原始值,支持事务回滚和MVCC。

EXPLAIN命令的关键指标包括type、key、rows和Extra。1)type反映查询的访问类型,值越高效率越高,如const优于ALL。2)key显示使用的索引,NULL表示无索引。3)rows预估扫描行数,影响查询性能。4)Extra提供额外信息,如Usingfilesort提示需要优化。

Usingtemporary在MySQL查询中表示需要创建临时表,常见于使用DISTINCT、GROUPBY或非索引列的ORDERBY。可以通过优化索引和重写查询避免其出现,提升查询性能。具体来说,Usingtemporary出现在EXPLAIN输出中时,意味着MySQL需要创建临时表来处理查询。这通常发生在以下情况:1)使用DISTINCT或GROUPBY时进行去重或分组;2)ORDERBY包含非索引列时进行排序;3)使用复杂的子查询或联接操作。优化方法包括:1)为ORDERBY和GROUPB


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

SublimeText3 Linux新版
SublimeText3 Linux最新版

Dreamweaver CS6
视觉化网页开发工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。