在介紹這個參數前,咱們先聊聊參數log_warnings。咱們知道MySQL中,其中log_error定義是否啓用錯誤日誌的功能和錯誤日誌的存儲位置,log_warnings定義是否將告警信息(warning messages)也寫入錯誤日誌。此選項默認啓用,具體來講:html
log_warnings 爲0, 表示不記錄告警信息。mysql
log_warnings 爲1, 表示告警信息寫入錯誤日誌。sql
log_warnings 大於1, 表示各種告警信息,例若有關網絡故障的信息和從新鏈接信息寫入錯誤日誌。安全
注意,此參數在不一樣版本略有差異,在MySQL 5.6中,log_warnings的默認值爲1,以下所示:服務器
Property網絡 |
Valueapp |
Command-Line Formatide |
--log-warnings[=#]this |
System Variablespa |
|
Scope (>= 5.6.4) |
Global |
Scope (<= 5.6.3) |
Global, Session |
Dynamic |
Yes |
Type (64-bit platforms) |
integer |
Type (32-bit platforms) |
integer |
Default Value (64-bit platforms) |
1 |
Default Value (32-bit platforms) |
1 |
Minimum Value (64-bit platforms) |
0 |
Minimum Value (32-bit platforms) |
0 |
Maximum Value (64-bit platforms) |
18446744073709551615 |
Maximum Value (32-bit platforms) |
4294967295 |
在MySQL 5.7中,有些版本默認值爲2,有些版本默認值爲1, 具體參考官方文檔信息,以下所示:
Property |
Value |
Command-Line Format |
--log-warnings[=#] |
Deprecated |
5.7.2 |
System Variable |
|
Scope |
Global |
Dynamic |
Yes |
Type (64-bit platforms) |
integer |
Type (32-bit platforms) |
integer |
Default Value (64-bit platforms, >= 5.7.2) |
2 |
Default Value (64-bit platforms, <= 5.7.1) |
1 |
Default Value (32-bit platforms, >= 5.7.2) |
2 |
Default Value (32-bit platforms, <= 5.7.1) |
1 |
Minimum Value (64-bit platforms) |
0 |
Minimum Value (32-bit platforms) |
0 |
Maximum Value (64-bit platforms) |
18446744073709551615 |
Maximum Value (32-bit platforms) |
4294967295 |
Print out warnings such as Aborted connection... to the error log. This option is enabled (1) by default. To disable it, use --log-warnings=0. Specifying the option without a level value increments the current value by 1. Enabling this option by setting it greater than 0 is recommended, for example, if you use replication (you get more information about what is happening, such as messages about network failures and reconnections). If the value is greater than 1, aborted connections are written to the error log, and access-denied errors for new connection attempts are written. See Section B.5.2.11, 「Communication Errors and Aborted Connections」.
If a slave server was started with --log-warnings enabled, the slave 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. The server logs messages about statements that are unsafe for statement-based logging if --log-warnings is greater than 0.
將告警信息,例如鏈接中斷等告警信息輸出到錯誤日誌。該選項默認啓用(默認值爲1)。要禁用它,請使用--log-warnings = 0選項。指定沒有級別值的選項時,將當前值遞增1. 推薦將這個值設置爲大於0啓用告警日誌信息寫入錯誤日誌。舉個例子,若是你正在使用複製(你將會獲取正在發生的事情的更多詳細信息,例若有關網絡故障的信息和從新鏈接信息)。若是該值大於1,鏈接中斷將寫入錯誤日誌,新的鏈接嘗試訪問的拒絕訪問信息。參見第B.5.2.11節「通訊錯誤和停止鏈接」。
若是從服務器(slave server)啓動時啓用了--log-warnings,則從設備將消息輸出到錯誤日誌中以提供有關其狀態的信息,例如二進制日誌和中繼日誌座標,它在開始做業時切換到另外一箇中繼日誌,斷開鏈接後從新鏈接等等。若是--log-warnings大於0,服務器將記錄關於對基於語句的日誌不安全的語句的消息。
注意:從MySQL 5.7.2開始,首選log_error_verbosity系統變量,而不是使用--log-warnings選項或log_warnings系統變量,這個參數從MySQL 8.0.3開始被移除了:
This system variable was removed in MySQL 8.0.3. Use the log_error_verbosity system variable instead.
而新參數log_error_verbosity更簡單,它有三個可選值, 分別對應:1 錯誤信息;2 錯誤信息和告警信息; 3:錯誤信息、告警信息和通知信息。 具體參考官方文檔,下面部分截取官方文檔。
Property |
Value |
Command-Line Format |
--log-error-verbosity=# |
System Variable |
|
Scope |
Global |
Dynamic |
Yes |
SET_VAR Hint Applies |
No |
Type |
integer |
Default Value (>= 8.0.4) |
2 |
Default Value (<= 8.0.3) |
3 |
Minimum Value |
1 |
Maximum Value |
3 |
The verbosity for handling events intended for the error log, as filtered by the log_filter_internal error log filter component. log_error_verbosity has no effect if log_filter_internal is not enabled.
The following table shows the permitted verbosity values.
Desired Log Filtering |
log_error_verbosity Value |
Error messages |
1 |
Error and warning messages |
2 |
Error, warning, and note messages |
3 |
Selected important system messages about non-error situations, such as startup and shutdown messages, are printed to the error log when the variable value is 1.
For additional information, see Section 5.4.2.5, 「Error Log Filtering」, and Section 5.5.1, 「Error Log Components」.
參考資料:
https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_log_warnings
https://dev.mysql.com/doc/refman/5.7/en/server-options.html#option_mysqld_log-warnings