MySQL管理工具MySQL Utilities — 解析MySQL日志文件

默北 MySQLMySQL管理工具MySQL Utilities — 解析MySQL日志文件已关闭评论10,4522字数 1550阅读5分10秒阅读模式

mysql.utilities.parser  模块提供了解析MySQL日志文件的类。目前,慢查询日志和通用查询日志都是支持的。

class mysql.utilities.parser.GeneralQueryLog(stream)

这个类解析MySQL 通用查询日志。实例是可以迭代的,不过该类不提供多个独立的迭代器的。如读取日志并打印数目:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

>>> general_log = open("/var/lib/mysql/mysql.log")
>>> log = GeneralQueryLog(general_log)
>>> for entry in log:
...     print entry
文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Parameters:
  • stream (file type) – a valid file type; for example, the result of the built-in Python function open()

version文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Returns: Version of the MySQL server that produced the log
Return type: tuple

program文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Returns: Full path of the MySQL server executable
Return type: str

port文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Returns: TCP/IP port on which the MySQL server was listening
Return type: int

socket文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Returns: Full path of the MySQL server Unix socket
Return type: str

start_datetime文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Returns: Date and time of the first read log entry
Return type: datetime.datetime

lastseen_datetime文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Returns: Date and time of the last read log entry
Return type: datetime.datetime

class mysql.utilities.parser.SlowQueryLog(stream)

这个类解析MySQL慢查询日志的。实例是可以迭代的,不过该类不提供多个独立的迭代器的。如读取日志并打印数目:文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

>>> slow_log = open("/var/lib/mysql/mysql-slow.log")
>>> log = SlowQueryLog(slow_log)
>>> for entry in log:
...     print entry
文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Parameters:
  • stream (file type) – a valid file type; for example, the result of the built-in Python function open()

version文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Returns: Version of the MySQL server that produced the log
Return type: tuple

program文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/

文章源自运维生存时间-https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/
Returns: Full path of the MySQL server executable
Return type: str

port

Returns: TCP/IP port on which the MySQL server was listening
Return type: int

socket

Returns: Full path of the MySQL server Unix socket
Return type: str

start_datetime

Returns: Date and time of the first read log entry
Return type: datetime.datetime

lastseen_datetime

Returns: Date and time of the last read log entry
Return type: datetime.datetime
weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 13/05/2015 01:00:59
  • 转载请务必保留本文链接:https://www.ttlsa.com/mysql/mysql-utilities-parse-mysql-log-file/