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主从 ...
随机推荐
- PHP的错误机制总结
PHP的错误机制也是非常复杂的,做了几年php,也没有仔细总结过,现在就补上这一课. 特别说明:文章的PHP版本使用5.5.32 PHP的错误级别 首先需要了解php有哪些错误.截至到php5.5,一 ...
- 测试几个xml的问题
使用sql server的时候,免不了与xml的参数打交道,xml大多数时候都给我们的程序带来方便,但是也有些时候会有变量赋值不通过的时候.(当然罗,如果你本身xml都通不过 xml spy 之类软件 ...
- SQL Server 2008 R2——使用FOR XML PATH实现多条信息按指定格式在一行显示
=================================版权声明================================= 版权声明:原创文章 谢绝转载 请通过右侧公告中的“联系邮 ...
- 001.mysql安装(lnmp)
mysql官方网站:http://dev.mysql.com/downloads/ Linux环境:刚安装的32位的“最小化安装“的CentOS 6.7 mysql版本:本次实验安装的是mysql5. ...
- Nagios监控平台搭建
Nagios是一款开源的免费网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员, ...
- Linux 信号(三)—— sigaction 函数
ilocker:关注 Android 安全(新入行,0基础) QQ: 2597294287 #include <signal.h> int sigaction(int signo, con ...
- WPF文章资源库
MUHAMMAD SHUJAAT SIDDIQI
- UVALive 4431 Fruit Weights --floyd,差分约束?
题意: 给出一些关系用aX <= bY表示, 最后查询aX 和 bY的关系,是>=,==,<=,还是不能确定,还是出现了矛盾. 解法:对每一个关系其实都可以建一条X->Y的边, ...
- 生产环境使用 pt-table-checksum 检查MySQL数据一致性
公司数据中心从托管机房迁移到阿里云,需要对mysql迁移(Replication)后的数据一致性进行校验,但又不能对生产环境使用造成影响,pt-table-checksum 成为了绝佳也是唯一的检查工 ...
- visualstudio 2013 mysql entityframeword :实体模型无法添加,闪退
发现电脑中安装的mysql-connector-net,版本为6.9.8 1.卸载此版本 2.重新安装mysql-connector-net 6.8.3 3.注意web.config中版本 4.注意项 ...

