如何通过grep 获取MySQL错误日志信息
发表于:2024-10-27 作者:千家信息网编辑
千家信息网最后更新 2024年10月27日,小编给大家分享一下如何通过grep 获取MySQL错误日志信息,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!为方便维护My
千家信息网最后更新 2024年10月27日如何通过grep 获取MySQL错误日志信息
小编给大家分享一下如何通过grep 获取MySQL错误日志信息,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
为方便维护MySQL,写了个脚本用以提供收集错误信息的接口。这些错误信息来自与MySQL错误日志,而 通过grep mysql可以获取error-log的路径。
#!/usr/bin/env python2.7#-*- encoding: utf-8 -*-"""该模块用于提取每天mysql日志中的异常或错误信息author: xiaomoemail: moxiaomomo@gmail.com"""import osimport sysimport stringfrom datetime import *# 預設字符解碼器為utf-8reload(sys)sys.setdefaultencoding('utf-8') COMMON_FLAGS = ["error", "exception", "fail", "crash", "repair"]def _contain_flag(cur_str): for flag in COMMON_FLAGS: if flag in string.lower(cur_str): return True return False"""获取当前mysql实例的error_log文件路径"""def _get_mysql_error_log_path(): log_path = '' grep_infos = os.popen('ps aux | grep mysql | grep "log-error"').read() if len(grep_infos) > 1: grep_infos = grep_infos.split("log-error=") if len(grep_infos) > 1: grep_infos = grep_infos[1].split(' ') if len(grep_infos) > 1: log_path = grep_infos[0] return log_path"""读取mysql错误日志中包含异常或错误信息的行"""def _get_error_info(error_log, begin_date): error_infos = [] f = open(error_log, 'r') lines = f.readlines() for line in lines: data_array = line.split(' ') if len(data_array) > 0 and len(data_array[0]) == 10: dt_strs = data_array[0].split('-') cur_date = date(int(dt_strs[0]), int(dt_strs[1]), int(dt_strs[2])) if cur_date >= begin_date and _contain_flag(line): error_infos.append(line) f.close() return error_infos"""组装并返回mysql错误日志信息"""def get_mysql_errors(begin_date=date.today()-timedelta(1)): try: err_log_path = _get_mysql_error_log_path() if len(err_log_path) > 1: return _get_error_info(err_log_path, begin_date) except Exception,e: print "[get_mysql_errors]%s"%e return []
以上是如何通过grep 获取MySQL错误日志信息的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
错误
信息
日志
内容
篇文章
路径
不怎么
大部分
字符
实例
接口
文件
更多
模块
用以
知识
脚本
行业
资讯
资讯频道
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
在线下载tcga数据库
华为服务器服务热线电话人工服务
浙江网络安全生产学院app
慈溪敏捷软件开发流程
魔兽世界一直显示服务器不兼容
沧州网络技术排名
网络安全工程专业有哪些
电脑服务器需要注意什么
金华学软件开发需要学什么
足球加软件开发
服务器数据转移麻烦吗
辽宁网络安全技能大赛
云顶手游在哪选择服务器
数据库和表单系统
风清气正的网络安全
网络安全与舆情是什么
联想服务器管理口设置IP
深信服网络安全管理设备
黑龙江pdu服务器电源价格表
web服务器创建新网页内容不变
做一个病毒软件开发
网络安全员工作怎么样
免费数据库入口
表格查看重复的数据库
网络安全人物周鸿祎
软件开发ea工具
靠谱的分布式数据库技术
精准投网络技术有限公司
管理证书服务器实验报告
美国云服务器一个月9元