MySQL 服务器有几个日志可以帮助你找出正在进行的活动。MySQL Server has several logs that can help you find out what activity is taking place.
| 日志类型Log Type | 写入日志的信息Information Written to Log |
|---|---|
| 错误日志Error log | 启动、运行或停止 mysqld 时遇到的问题Problems encountered starting, running, or stopping mysqld |
| 常规查询日志General query log | 已建立的客户端连接和从客户端接收的语句Established client connections and statements received from clients |
| 二进制日志Binary log | 更改数据的语句(也用于复制)Statements that change data (also used for replication) |
| 中继日志Relay log | 从复制源服务器接收的数据更改Data changes received from a replication source server |
| 慢查询日志Slow query log | 执行时间超过 long_query_time 秒的查询Queries that took more than
long_query_time seconds to
execute |
| DDL 日志DDL logs | 由 DDL 语句执行的原子 DDL 操作Atomic DDL operations performed by DDL statements |
默认情况下,不启用任何日志,除非在 Windows 上的错误日志。有关 DDL 日志行为的信息,请参见 查看 DDL 日志。以下与日志相关的部分提供有关启用日志记录的服务器选项的信息。By default, no logs are enabled, except the error log on Windows. For information about DDL log behavior, see Viewing DDL Logs. The following log-specific sections provide information about the server options that enable logging.
默认情况下,服务器会在数据目录中为所有启用的日志写入文件。您可以通过刷新日志来强制服务器关闭并重新打开日志文件(在某些情况下切换到新日志文件)。当您发出FLUSH LOGS语句时,执行带有flush-logs或refresh参数的mysqladmin,或执行带有--flush-logs选项的mysqldump时,都会发生日志刷新。请参阅第 15.7.8.3 节,“FLUSH 语句”、第 6.5.2 节,“mysqladmin — MySQL Server 管理程序”,以及第 6.5.4 节,“mysqldump — 数据库备份程序”。此外,当二进制日志的大小达到系统变量max_binlog_size的值时,也会刷新二进制日志。By default, the server writes files for all enabled logs in the data
directory. You can force the server to close and reopen the log
files (or in some cases switch to a new log file) by flushing the
logs. Log flushing occurs when you issue a
FLUSH LOGS statement; execute
mysqladmin with a flush-logs
or refresh argument; or execute
mysqldump with a
--flush-logs option. See
Section 15.7.8.3, “FLUSH Statement”, Section 6.5.2, “mysqladmin — A MySQL Server Administration Program”, and
Section 6.5.4, “mysqldump — A Database Backup Program”. In addition, the binary log is flushed
when its size reaches the value of the
max_binlog_size system variable.
您可以在运行时控制通用查询日志和慢查询日志。您可以启用或禁用日志记录,或者更改日志文件名。您可以告诉服务器将通用查询和慢查询条目写入日志表、日志文件或两者兼而有之。详情请参见 第 7.4.1 节,“选择通用查询日志和慢查询日志输出位置”、第 7.4.3 节,“通用查询日志” 以及 第 7.4.5 节,“慢查询日志”。You can control the general query and slow query logs during runtime. You can enable or disable logging, or change the log file name. You can tell the server to write general query and slow query entries to log tables, log files, or both. For details, see Section 7.4.1, “Selecting General Query Log and Slow Query Log Output Destinations”, Section 7.4.3, “The General Query Log”, and Section 7.4.5, “The Slow Query Log”.
中继日志仅在副本上使用,用于保存来自复制源服务器的数据更改,这些更改也必须在副本上执行。有关中继日志内容和配置的讨论,请参见 第 19.2.4.1 节,“中继日志”。The relay log is used only on replicas, to hold data changes from the replication source server that must also be made on the replica. For discussion of relay log contents and configuration, see Section 19.2.4.1, “The Relay Log”.
有关日志维护操作的信息,如旧日志文件的过期,请参见 第 7.4.6 节,“服务器日志维护”。For information about log maintenance operations such as expiration of old log files, see Section 7.4.6, “Server Log Maintenance”.
有关保持日志安全的信息,请参见 第 8.1.2.3 节,“密码与日志记录”。For information about keeping logs secure, see Section 8.1.2.3, “Passwords and Logging”.