logging in mysql (outdated slideset)

13
MySQL 5.6 Log Files Kristian Köhntopp

Upload: kristian-koehntopp

Post on 22-Jan-2017

409 views

Category:

Internet


1 download

TRANSCRIPT

Page 1: Logging in MySQL (outdated slideset)

MySQL 5.6 Log FilesKristian Köhntopp

Page 2: Logging in MySQL (outdated slideset)

Logfiles

• End up in $datadir, may contain hostname

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

2

Page 3: Logging in MySQL (outdated slideset)

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

Page 4: Logging in MySQL (outdated slideset)

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

Page 5: Logging in MySQL (outdated slideset)

Slow Log

• Goes into same destination as general log

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

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

5

Page 6: Logging in MySQL (outdated slideset)

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

Page 7: Logging in MySQL (outdated slideset)

Slow Log

• mysqldumpslow:

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

7

Page 8: Logging in MySQL (outdated slideset)

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

Page 9: Logging in MySQL (outdated slideset)

Binary Log

• Log of all data changing statements

• Used in replication

• Used for point-in-time recovery

• Read by mysqlbinlog Command Line Tool

9

Page 10: Logging in MySQL (outdated slideset)

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

Page 11: Logging in MySQL (outdated slideset)

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

Page 12: Logging in MySQL (outdated slideset)

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

Page 13: Logging in MySQL (outdated slideset)

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