Logging in MySQL (outdated slideset)

Post on 22-Jan-2017

403 views 1 download

Transcript of Logging in MySQL (outdated slideset)

MySQL 5.6 Log FilesKristian Köhntopp

Logfiles

• End up in $datadir, may contain hostname

• All of that needs to be configured away, because it makes cloning hard.

2

Logfiles3

General Log All server commands, generally TMI

Slow Query Log Long running queries, and queries w/ no index use

Error Log All server error messages

Binary Log Write commands, for recovery and replication

General Log

• Log can do into a file or a table

• --log-output = FILE,TABLE,NONE

• Turn on logging

• --general-log = 1 (0 for off)

• Log file name

• --general-log-file = file

• goes to $datadir, if no path included

4

Slow Log

• Goes into same destination as general log

• --slow-query-log = 1 (0 for off)

• --slow-query-log-file = file

5

Slow Log

• What to log:

• --long-query-time = …

• Starts at 0, unit microseconds

• --log-queries-not-using indexes

• Useful only with--min-examined-row-limit = …

• --log-slow-admin-statements

• Generally useless

6

Slow Log

• mysqldumpslow:

• Command Line Tool (perl) to analyze the slow log

7

Error Log

• --log-error = file

• or --console (use stderr)

• or --syslog (use syslog)

• Windows also logs to Event Log

• INFO is not logged to Event Log

8

Binary Log

• Log of all data changing statements

• Used in replication

• Used for point-in-time recovery

• Read by mysqlbinlog Command Line Tool

9

Binary Log

• --binlog-format= STATEMENT|ROW|MIXED

• --log-bin=file

• Basename, becomes file.000000

• --max-binlog-size = 1G

• Next binlog started at this filesize

• --expire_logs_days = 7

• Throws away old binlogs.

10

Log Rotation

• FLUSH LOGS;

• closes and reopens all log files

• also moves error.log to error.log-old in order to work around Windows issues

11

Log Rotation

• New binlog file started on

• server start OR flush logs OR file > max_binlog_size

• Old binlogs expired when

• file older than expire_logs_days AND

• new binlog started

12

Tips and Tricks

• As of 5.1, logging can be controlled at runtime.

• As of 5.1, slow log can be controlled w/ microsecond accuracy.

• Logging to a table is slow, and limited.

• Learn mysqldumpslow.

• Check the error log.

13