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主从 ...
随机推荐
- ELF Format 笔记(十三)—— 段权限
ilocker:关注 Android 安全(新手) QQ: 2597294287 一个可被系统加载的程序至少拥有一个可加载段.当系统创建可加载段的内存映像时,会根据 p_flags 赋予一定的访问权限 ...
- [mysql]三种方法为root账户指定密码
前言:前段时间把mysql安装后一直没管它,当时就在奇怪为什么mysql登陆不要密码,原来一直用的超用户账户登陆的(简称超级用户) 其实只怪自己太无知,之前一直用的phpbydamin进行的数据库的可 ...
- Java连接SQLServer2008终极解决办法(亲身上机演练版)
今天我一学妹问我,Java连接SQLServer2008数据库的问题,一直无法连接成功.想起自己刚开始学习的时候,在网上找各种文章,然后实际上机验证操作,花了一两天时间才搞定,一把辛酸泪呀!记得当时是 ...
- 【WPF系列】基础学习-WPF架构概览
引言 WPF从.net framewok3.0加入以来,经历了很多跟新.每次更新都给用户带来了新的功能或者优化性能.下面我们首先看下WPF再.netFramework中的位置,接着介绍下WPF的架构框 ...
- 【2016-10-31】【坚持学习】【Day16】【MongoDB】【入门】
下载,安装: http://www.mongodb.org/downloads 命令行下运行 MongoDB 服务器 为了从命令提示符下运行MongoDB服务器,你必须从MongoDB目录的bin目录 ...
- pyqt5-为QListWidget添加右键菜单
如何在pyqt5下为QListWidget添加右键菜单? 能百度到的均是pyqt4下的,有些貌似并不好用. 在尝试了很多方法后,下面贴出可用的方法: from PyQt4 import QtCore, ...
- 第7章 权限管理(3)_文件系统属性和sudo权限
3. 文件系统属性chattr权限 (1)chattr命令 命令格式: #chattr [+-=][选项] 文件或目录名 +.-.= 分别表示增加权限.删除权限和赋于某种权限 选项 i:主要用来防止对 ...
- Object.assign方法复制或合并对象
Object.assign() 方法可以把任意多个的源对象自身的可枚举属性拷贝给目标对象,然后返回目标对象 var obj = { a: 1 }; var copy = Object.assign({ ...
- Python 字符串
Python访问字符串中的值 Python不支持单字符类型,单字符也在Python也是作为一个字符串使用. Python访问子字符串,可以使用方括号来截取字符串,如下实例: #!/usr/bin/py ...
- jS字符串大小写转换实现方式
toLocaleUpperCase 方法:将字符转换为大写 stringVar.tolocaleUpperCase( ) 必选的 stringVar 引用是一个 String 对象,值或文字. //转 ...

