MySQL Variables log_warnings 数据库 参数变量解释及正确配置使用

本站中文解释

在MySQL服务器中,log_warnings参数变量用于控制是否将警告信息写入日志文件中。设置log_warnings参数变量的方式如下:

1、在MySQL控制台中输入“SET GLOBAL log_warnings = 1”;

2、编辑MySQL的配置文件my.cnf,将log_warnings参数设置为1:

[mysqld]

log_warnings = 1

注:建议将参数log_warnings设置为1是因为它将向MySQL服务器提供有用的警告信息,可以帮助我们及时发现系统异常情况,并及时采取有效的措施以解决问题。

官方英文解释

log_warnings

Command-Line Format --log-warnings[=#]
Deprecated Yes
System Variable log_warnings
Scope Global
Dynamic Yes
Type Integer
Default Value 2
Minimum Value 0
Maximum Value (64-bit platforms) 18446744073709551615
Maximum Value (32-bit platforms) 4294967295

Whether to produce additional warning messages to the error
log. As of MySQL 5.7.2, information items previously governed
by log_warnings are governed
by log_error_verbosity, which
is preferred over, and should be used instead of, the older
log_warnings system variable.
(The log_warnings system
variable and --log-warnings
command-line option are deprecated; expect them to be removed
in a future release of MySQL.)

log_warnings is enabled by
default (the default is 1 before MySQL 5.7.2, 2 as of 5.7.2).
To disable it, set it to 0. If the value is greater than 0,
the server logs messages about statements that are unsafe for
statement-based logging. If the value is greater than 1, the
server logs aborted connections and access-denied errors for
new connection attempts. See
Section B.3.2.9, “Communication Errors and Aborted Connections”.

If you use replication, enabling this variable by setting it
greater than 0 is recommended, to get more information about
what is happening, such as messages about network failures and
reconnections.

If a replica server is started with
log_warnings enabled, the
replica prints messages to the error log to provide
information about its status, such as the binary log and relay
log coordinates where it starts its job, when it is switching
to another relay log, when it reconnects after a disconnect,
and so forth.

Assigning a value to
log_warnings assigns a value
to log_error_verbosity and
vice versa. The variables are related as follows:

  • Suppression of all
    log_warnings items,
    achieved with
    log_warnings=0, is
    achieved with
    log_error_verbosity=1
    (errors only).

  • Items printed for
    log_warnings=1 or higher
    count as warnings and are printed for
    log_error_verbosity=2 or
    higher.

  • Items printed for
    log_warnings=2 count as
    notes and are printed for
    log_error_verbosity=3.

As of MySQL 5.7.2, the default log level is controlled by
log_error_verbosity, which
has a default of 3. In addition, the default for
log_warnings changes from 1
to 2, which corresponds to
log_error_verbosity=3. To
achieve a logging level similar to the previous default, set
log_error_verbosity=2.

In MySQL 5.7.2 and higher, use of
log_warnings is still
permitted but maps onto use of
log_error_verbosity as
follows:

  • Setting log_warnings=0 is
    equivalent to
    log_error_verbosity=1
    (errors only).

  • Setting log_warnings=1 is
    equivalent to
    log_error_verbosity=2
    (errors, warnings).

  • Setting log_warnings=2
    (or higher) is equivalent to
    log_error_verbosity=3
    (errors, warnings, notes), and the server sets
    log_warnings to 2 if a
    larger value is specified.


数据运维技术 » MySQL Variables log_warnings 数据库 参数变量解释及正确配置使用