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

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

class mysql.utilities.parser.GeneralQueryLog(stream)

这个类解析MySQL 通用查询日志。实例是可以迭代的,不过该类不提供多个独立的迭代器的。如读取日志并打印数目:

>>> general_log = open("/var/lib/mysql/mysql.log")

>>> log = GeneralQueryLog(general_log)

>>> for entry in log:

... print entry

1

2

3

4

>>>general_log=open("/var/lib/mysql/mysql.log")

>>>log=GeneralQueryLog(general_log)

>>>forentryinlog:

...printentry

Parameters:

stream (file type) – a valid file type; for example, the result of the built-in Python function open()

version

Returns:

Version of the MySQL server that produced the log

Return type:

tuple

program

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

class mysql.utilities.parser.SlowQueryLog(stream)

这个类解析MySQL慢查询日志的。实例是可以迭代的,不过该类不提供多个独立的迭代器的。如读取日志并打印数目:

>>> slow_log = open("/var/lib/mysql/mysql-slow.log")

>>> log = SlowQueryLog(slow_log)

>>> for entry in log:

... print entry

1

2

3

4

>>>slow_log=open("/var/lib/mysql/mysql-slow.log")

>>>log=SlowQueryLog(slow_log)

>>>forentryinlog:

...printentry

Parameters:

stream (file type) – a valid file type; for example, the result of the built-in Python function open()

version

Returns:

Version of the MySQL server that produced the log

Return type:

tuple

program

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值