MySQL主从同步延迟
早上接到open-falcon报警,一台mysql从库同步延迟2w多秒,mysql版本比较老,用的5.1.37。
连接从库查找原因:
show processlist一下,查看哪些线程在跑。
看到Time=25565,也就是说这个线程保持当前状态25565秒,一直在执行Updating操作。怀疑是由php分析数据脚本引起的,把这条语句发给开发,问问执行的是什么操作,开发说是每个用户登录,游戏角色等级提高就执行一次update操作,又问开发有没有脚本执行这个update语句,开发也说不清。。没办法,只能去脚本机搜索定时任务中php脚本了,脚本非常多crontab -l 列出所有脚本,配合awk,grep搜索所有php脚本,然后过滤脚本中内容update,有几个是有update操作的,逐个分析,并查看脚本记录的日志。执行tail -f /opt/wwwroot/daemon/run/datasource/newdata/fast_channel_run.log时,发现了大量update的记录,又向开发确认下,原因基本确定,让开发优化php脚本了。

解决思路:
给开发提建议,优化程序逻辑,多个update合成一条语句执行。
降低update频率
升级mysql版本,mysql-5.1性能比新版差的太多,但短期不现实。
实在延迟跟不上了,重做了salve。
下面是show processlist的一些说明,摘自官方文档。
13.7.5.30. SHOW PROCESSLIST Syntax
SHOW [FULL] PROCESSLIST
SHOW PROCESSLIST shows you which threads are running. You can also get this information from the INFORMATION_SCHEMA PROCESSLIST table or the mysqladmin processlist command. If you have the PROCESS privilege, you can see all threads. Otherwise, you can see only your own threads (that is, threads associated with the MySQL account that you are using). If you do not use the FULL keyword, only the first 100 characters of each statement are shown in the Info field.
Process information is also available from the performance_schema.threads table. However, access to threads does not require a mutex and has minimal impact on server performance. INFORMATION_SCHEMA.PROCESSLIST and SHOW PROCESSLIST have negative performance consequences because they require a mutex. threads also shows information about background threads, which INFORMATION_SCHEMA.PROCESSLIST and SHOW PROCESSLIST do not. This means that threads can be used to monitor activity the other thread information sources cannot.
The SHOW PROCESSLIST statement is very useful if you get the “too many connections” error message and want to find out what is going on. MySQL reserves one extra connection to be used by accounts that have the SUPER privilege, to ensure that administrators should always be able to connect and check the system (assuming that you are not giving this privilege to all your users).
Threads can be killed with the KILL statement. See Section 13.7.6.4, “KILL Syntax”.
Here is an example of SHOW PROCESSLIST output:
mysql> SHOW FULL PROCESSLIST\G
*************************** 1. row ***************************
Id: 1
User: system user
Host:
db: NULL
Command: Connect
Time: 1030455
State: Waiting for master to send event
Info: NULL
The columns produced by SHOW PROCESSLIST have the following meanings:
IdThe connection identifier.
UserThe MySQL user who issued the statement. If this is
system user, it refers to a nonclient thread spawned by the server to handle tasks internally. This could be the I/O or SQL thread used on replication slaves or a delayed-row handler.unauthenticated userrefers to a thread that has become associated with a client connection but for which authentication of the client user has not yet been done.event_schedulerrefers to the thread that monitors scheduled events. Forsystem user, there is no host specified in theHostcolumn.HostThe host name of the client issuing the statement (except for
system userwhere there is no host).SHOW PROCESSLISTreports the host name for TCP/IP connections informat to make it easier to determine which client is doing what.host_name:client_portdbThe default database, if one is selected, otherwise
NULL.CommandThe type of command the thread is executing. For descriptions for thread commands, see Section 8.12.5, “Examining Thread Information”. The value of this column corresponds to the
COM_commands of the client/server protocol andxxxCom_status variables. See Section 5.1.6, “Server Status Variables”xxxTimeThe time in seconds that the thread has been in its current state.
StateAn action, event, or state that indicates what the thread is doing. Descriptions for
Statevalues can be found at Section 8.12.5, “Examining Thread Information”.Most states correspond to very quick operations. If a thread stays in a given state for many seconds, there might be a problem that needs to be investigated.
For the
SHOW PROCESSLISTstatement, the value ofStateisNULL.InfoThe statement the thread is executing, or
NULLif it is not executing any statement. The statement might be the one sent to the server, or an innermost statement if the statement executes other statements. For example, if aCALLstatement executes a stored procedure that is executing aSELECTstatement, theInfovalue shows theSELECTstatement.
MySQL主从同步延迟的更多相关文章
- MySQL 主从同步延迟监控
MySQL5.7和8.0支持通过 replication_applier_status 表获同步延迟时间,当从库出现延迟后,该表中的字段 REMAINING_DELAY 记录延迟秒数,当没有延迟时,该 ...
- [转载] 使用MySQL Proxy解决MySQL主从同步延迟
原文地址:http://koda.iteye.com/blog/682547 MySQL的主从同步机制非常方便的解决了高并发读的应用需求,给Web方面开发带来了极大的便利.但这种方式有个比较大的缺陷在 ...
- 使用MySQL Proxy解决MySQL主从同步延迟
MySQL的主从同步机制非常方便的解决了高并发读的应用需求,给Web方面开发带来了极大的便利.但这种方式有个比较大的缺陷在于MySQL的同步机制 是依赖Slave主动向Master发请求来获取数据的, ...
- 谈谈Mysql主从同步延迟分析及解决方案
一.MySQL的数据库主从复制原理 MySQL主从复制实际上基于二进制日志,原理可以用一张图来表示: 分为四步走: 1. 主库对所有DDL和DML产生的日志写进binlog: 2. 主库生成一个 lo ...
- 深入解析Mysql 主从同步延迟原理及解决方案
MySQL的主从同步是一个很成熟的架构,优点为:①在从服务器可以执行查询工作(即我们常说的读功能),降低主服务器压力;②在从主服务器进行备份,避免备份期间影响主服务器服务;③当主服务器出现问题时,可以 ...
- mysql主从同步(3)-percona-toolkit工具(数据一致性监测、延迟监控)使用梳理
转自:http://www.cnblogs.com/kevingrace/p/6261091.html 在mysql工作中接触最多的就是mysql replication mysql在复制方面还是会有 ...
- MySQL主从同步的延迟原理
1. MySQL数据库主从同步延迟原理. 答:谈到MySQL数据库主从同步延迟原理,得从mysql的数据库主从复制原理说起,mysql的主从复制都是单线程的操作,主库对所有DDL和DML产生binlo ...
- mysql主从同步(4)-Slave延迟状态监控
mysql主从同步(4)-Slave延迟状态监控 转自:http://www.cnblogs.com/kevingrace/p/5685511.html 之前部署了mysql主从同步环境(Mysql ...
- mysql主从同步(5)-同步延迟状态考量(seconds_behind_master和pt-heartbea)
一般情况下,我们是通过"show slave status \G;"提供的Seconds_Behind_Master值来衡量mysql主从同步的延迟情况.具体说明见:mysql主从 ...
随机推荐
- SQL SERVER CHAR ( integer_expression )各版本返回值差异的案例
我们都知道CHAR(integer_expression)将ASCII代码转换为字符.当integer_expression介于 0 和 255 之间的整数.如果该整数表达式不在此范围内,将返回 NU ...
- MS SQL巡检系列——检查数据库上一次DBCC CHECKDB的时间
DBCC CHECKDB检查指定数据库中的所有对象的逻辑和物理完整性,具体请参考MSDN文档.我们必须定期对数据库做完整性检查(DBCC CHECKDB),以便能及时发现一些数据库损坏(Corrupt ...
- ANDROID STDUIO 项目里的R文件突然丢失的解决办法N种之一
刚刚项目里的R文件突然挂了,清理项目,关闭重开Studio,都不能解决.快没折了. 然后只好在项目上右击,看看有没有解决的办法.发现有个 Make Module ,姑且试试吧. 结果,竟然修复了.这是 ...
- 常见博客API
新浪博客 http://upload.move.blog.sina.com.cn/blog_rebuild/blog/xmlrpc.php 网易博客 http://os.blog.163.com/ap ...
- css3 选择器(三)
接css3选择器(一) 接css3 选择器(二) 这篇和前两篇内容相关性不大,主要是涉及到一些css3的状态选择器,所以标题从一开始. 一.[:enabled]选择器 一看这个属性就知道是专为表单元素 ...
- AngularJS笔记---注册服务
在前面的笔记中,了解到AngularJS的后台控制可以在Controller里面实现. 可是如果所有的逻辑代码都写到Controller会显得该Controller过于臃肿. 不方便维护, Angul ...
- BZOJ1500: [NOI2005]维修数列[splay ***]
1500: [NOI2005]维修数列 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 12278 Solved: 3880[Submit][Statu ...
- Unity Shader入门
Unity Shader入门 http://www.cnblogs.com/lixiang-share/p/5025662.html http://www.manew.com/blog-30559-1 ...
- 关于JSP---三大指令
JSP三大指令: page ------>最复杂的一个指令,属性很多,常用的像import,language,pageEncoding等等 include-------->静态包含, ...
- jquery修改css样式,样式带!important
由于需求的需要,今天在用jquery修改一个弹出框的样式的时候,由于有一个按钮有padding-left:12px;导致内间距空出来的这一块颜色用普通的方式无法改变. 普通的jquery修改css的方 ...

