Skip to main content

MySQL Log

Project description

MySQLog

MySQLog is command line program used to collect mysql slow query log like Porcona Toolkit's pt-query-digest.

Usage: mysqlog [OPTIONS] LOGPATH

Arguments:
  LOGPATH  [required]

Options:
  -e, --env TEXT                  [default: default]
  -u, --user TEXT                 [required]
  -p, --password TEXT             [required]
  -h, --host TEXT                 [default: localhost]
  -P, --port INTEGER              [default: 3306]
  -d, --database TEXT             [default: test]
  -t, --thread-size INTEGER       [default: 1]
  --install-completion [bash|zsh|fish|powershell|pwsh]
                                  Install completion for the specified shell.
  --show-completion [bash|zsh|fish|powershell|pwsh]
                                  Show completion for the specified shell, to
                                  copy it or customize the installation.
  --help                          Show this message and exit.

Install

# create python virtual environment for mysqlog
python3 -m venv  mysqlog.venv
# active virtual environment mysqlog.venv 
source mysqlog.venv/bin/activate
# use pip command install mysqlog
pip install mysqlog
# check mysqlog is installed
mysqlog --help

Usage

  1. Example log file (mysql-slow.log)
# Time: 2020-09-25T06:05:23.747686Z
# User@Host: root[root] @  [10.190.66.171]  Id:     7
# Query_time: 4.412855  Lock_time: 0.000136 Rows_sent: 3  Rows_examined: 8720446
SET timestamp=1601013923;
SELECT id FROM `xxl_job_log`
                WHERE !(
                        (trigger_code in (0, 200) and handle_code = 0)
                        OR
                        (handle_code = 200)
                )
                AND `alarm_status` = 0
                ORDER BY id ASC;
  1. Init Database
# connect to mysql
mysql -uroot -p123456
# create database and use it
mysql> create database test;
mysql> use database test;
# create mysql_slow_query_log table
mysql> CREATE TABLE `mysql_slow_query_log` (
        `id` int NOT NULL auto_increment,
        `md5` VARCHAR(64) NOT NULL comment 'md5',
        `datetime` DATETIME NOT NULL comment '执行时间',
        `database` VARCHAR(50) NULL comment '数据库',
        `user`  VARCHAR(50) NULL comment '数据库用户',
        `host` VARCHAR(100) NULL comment '数据库主机',
        `query` TEXT NOT NULL comment '执行语句',
        `query_time` FLOAT DEFAULT NULL comment '执行时间',
        `lock_time` FLOAT DEFAULT NULL comment '锁定时间',
        `rows_examined` INT DEFAULT NULL comment '扫描总行数',
        `rows_sent` INT DEFAULT NULL comment '返回总行数',
        `created_at` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
        PRIMARY KEY (`id`),
        UNIQUE KEY (`md5`)
      );
# make sure mysql_slow_query_log table is created
mysql> show tables;
  1. Run MySQLog
mysqlog -uroot -p123456 -hlocalhost -dtest mysql-slow.log

FAQ

  1. how to enable mysql's slow query log

  2. how to know mysql's slow query log file's location

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mysqlog-1.0.3.tar.gz (13.9 kB view details)

Uploaded Source

Built Distributions

mysqlog-1.0.3-py3.9.egg (22.4 kB view details)

Uploaded Source

mysqlog-1.0.3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file mysqlog-1.0.3.tar.gz.

File metadata

  • Download URL: mysqlog-1.0.3.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for mysqlog-1.0.3.tar.gz
Algorithm Hash digest
SHA256 4a0de84b0ebbcee7a2199978e75479ae5a467d5dcfc0b6772cfbbb3a2e700259
MD5 8be69e040915292cdcab42f76182dd24
BLAKE2b-256 c3050a3deecd4291f16f105b345b692f377efa8cac49ec926355fd8a6855e369

See more details on using hashes here.

File details

Details for the file mysqlog-1.0.3-py3.9.egg.

File metadata

  • Download URL: mysqlog-1.0.3-py3.9.egg
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for mysqlog-1.0.3-py3.9.egg
Algorithm Hash digest
SHA256 e807c4e5a382bbf4e6e535414f603a9b993577e2091e3b22987dfd637d8df211
MD5 acdb697f5007fb1d4e2132e20f7e23ff
BLAKE2b-256 69f3fe6a8b7c50917391d4a8269d5e0c6b0a802f3105e096f28208262d0d9734

See more details on using hashes here.

File details

Details for the file mysqlog-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: mysqlog-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for mysqlog-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 72ee4cf4858019dfd9f5c65b23863a7b1705c1d994d1942ce272bf7cfb6944bb
MD5 d87dc00b5826e09a7567ccaa7294ee8a
BLAKE2b-256 65a53087ec5c05f0ddf6d93fc0ae54c06d18bbe1f75ecf39f8442aa15968bb7e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page