In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
To facilitate the maintenance of MySQL, a script is written to provide an interface for collecting error messages. These error messages come from the MySQL error log, and the path to the error-log can be obtained through grep mysql.
Here is all the relevant code:
#! / usr/bin/env python2.7#-*- encoding: utf-8-*-"" this module is used to extract exception or error messages from daily mysql logs author: xiaomoemail: moxiaomomo@gmail.com "" import osimport sysimport stringfrom datetime import * # default character parser is 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 "" get the error_log file path of the current mysql instance "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 "" read lines in the mysql error log containing exception or error messages "" 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 "" assemble and return mysql error log message "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 []
If you are interested, please refer to us and thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.