no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | mysql_logs [2013/10/03 18:37] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== MySQL Logs ====== | ||
+ | * [[MySQL]] | ||
+ | * [[MySQL Configuration]] | ||
+ | * [[MySQL Optimization]] | ||
+ | * [[maatkit]] | ||
+ | * [[logrotate]] | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | By default, MySQL doesn' | ||
+ | |||
+ | All logs need to be properly secured, since they can contain sensitive data within queries. | ||
+ | |||
+ | Logs can quickly grow in size, especially slow queries if watching for rows that don't use indexes on lookups. | ||
+ | |||
+ | ==== Slow Query Log ==== | ||
+ | |||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | * [[http:// | ||
+ | |||
+ | The default value for a query to take before being logged is 10 seconds. | ||
+ | |||
+ | Setup slow query logging in '' | ||
+ | |||
+ | < | ||
+ | log-slow-queries = / | ||
+ | long_query_time = 1 | ||
+ | </ | ||
+ | |||
+ | You can also log slow administrative statements: | ||
+ | |||
+ | < | ||
+ | log-slow-admin-statements | ||
+ | </ | ||
+ | |||
+ | Include queries that do not use indexes for row lookups in the statements: | ||
+ | |||
+ | < | ||
+ | log-queries-not-using-indexes | ||
+ | </ | ||
+ | |||
+ | ==== Error Log ==== | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | The error log contains information indicating when mysqld was started and stopped and also any critical errors that occur while the server is running. If mysqld notices a table that needs to be automatically checked or repaired, it writes a message to the error log. | ||
+ | |||
+ | You can specify where mysqld writes the error log with the '' | ||
+ | |||
+ | Setup error logging in '' | ||
+ | |||
+ | < | ||
+ | log-error=/ | ||
+ | </ | ||
+ | |||
+ | ==== General Query Log ==== | ||
+ | |||
+ | Enable the general query log without restarting the database: | ||
+ | |||
+ | < | ||
+ | SHOW VARIABLES LIKE ' | ||
+ | SET GLOBAL general_log_file = '/ | ||
+ | SET GLOBAL general_log = 1; | ||
+ | </ | ||
+ | ==== Binary Log ==== | ||
+ | |||
+ | * [[http:// | ||
+ | |||
+ | Binary log is recommended for aiding to restore data. | ||
+ | |||
+ | You can remove all the binary logs if desired: | ||
+ | |||
+ | < | ||
+ | RESET MASTER; | ||
+ | </ | ||
+ | |||
+ | Purging a range of binary logs is also possible. | ||
+ | |||
+ | ==== Flushing Logs ==== | ||
+ | |||
+ | Binary logs are flushed automatically, | ||
+ | |||
+ | < | ||
+ | max_binlog_size = 100M | ||
+ | </ | ||
+ | |||
+ | Use mysqladmin, either '' | ||
+ | |||
+ | < | ||
+ | mysqladmin flush-logs | ||
+ | mysqladmin refresh | ||
+ | </ | ||
+ | |||
+ | Query: | ||
+ | |||
+ | < | ||
+ | FLUSH LOGS; | ||
+ | </ | ||
+ | ==== Log Rotation ==== | ||
+ | |||
+ | Percona ships with a logrotate configuration file located at ''/ | ||
+ | |||
+ | * Keeps 7 days worth of logs | ||
+ | * Rotates daily | ||
+ | * Compresses logs | ||
+ | |||
+ | == General Configuration == | ||
+ | |||
+ | Here's a sample file for ''/ | ||
+ | |||
+ | < | ||
+ | / | ||
+ | daily | ||
+ | rotate 30 | ||
+ | missingok | ||
+ | ifempty | ||
+ | sharedscripts | ||
+ | create 660 mysql mysql | ||
+ | postrotate | ||
+ | / | ||
+ | endscript | ||
+ | } | ||
+ | </ |