MariaDB SQL Error Log Pluginシステム変数を変更する方法
MariaDB SQL Error Log Pluginは、MariaDBサーバーのエラーログを記録するためのプラグインです。このプラグインは、エラーメッセージだけでなく、エラーが発生したSQLステートメントやバックトレース情報も記録することができます。
このチュートリアルでは、MariaDB SQL Error Log Pluginシステム変数を変更する方法を説明します。これらの変数は、プラグインの動作を制御するために使用されます。
前提条件
このチュートリアルを始める前に、以下の前提条件を満たしていることを確認してください。
- MariaDBサーバーがインストールされている。
- rootユーザーまたは管理権限を持つユーザーとしてログインしている。
手順
[log]
log-error=/var/log/mariadb/error.log
この行は、エラーログファイルの場所を指定します。デフォルトの場所は、/var/log/mariadb/error.log
です。
[log_error]
sql_err_log_level=4
sql_err_log_verbosity=3
これらの行は、エラーログに記録される情報量を制御します。
sql_err_log_level
は、記録されるエラーメッセージの重大度を制御します。デフォルト値は4で、すべてのエラーメッセージが記録されます。sql_err_log_verbosity
は、エラーメッセージに記録される情報量を制御します。デフォルト値は3で、エラーメッセージ、SQLステートメント、バックトレース情報が記録されます。
[error_log_plugins]
sql_error_log=1
この行は、SQL Error Log Pluginを有効にします。
- MariaDBサーバーを再起動します。
sudo systemctl restart mariadb
その他のシステム変数
以下のその他のシステム変数も使用できます。
sql_err_log_file_name
:エラーログファイルの名前を指定します。sql_err_log_rotate
:エラーログファイルが自動的にローテーションされるかどうかを制御します。sql_err_log_append
:新しいエラーメッセージが既存のエラーログファイルに追加されるかどうかを制御します。
詳細については、MariaDBのドキュメントを参照してください。
補足
- このチュートリアルでは、基本的なシステム変数のみを説明しています。詳細については、MariaDBのドキュメントを参照してください。
- システム変数を変更する前に、現在の設定をバックアップしておくことをお勧めします。
ご参考になりましたでしょうか?
[log]
log-error=/var/log/mariadb/error.log
[log_error]
sql_err_log_level=4
sql_err_log_verbosity=3
[error_log_plugins]
sql_error_log=1
This configuration will:
- Set the error log file to
/var/log/mariadb/error.log
. - Log all error messages (level 4).
- Log error messages, SQL statements, and backtrace information (verbosity 3).
- Enable the SQL Error Log Plugin.
To apply these changes, save the configuration file and then restart the MariaDB server:
sudo systemctl restart mariadb
Explanation of the configuration file:
- The
[log]
section defines the general settings for logging. In this case, we are only specifying the location of the error log file. - The
[log_error]
section defines the settings for the SQL Error Log Plugin. Thesql_err_log_level
variable specifies the minimum severity of error messages that will be logged. Thesql_err_log_verbosity
variable specifies the amount of information that will be logged for each error message. - The
[error_log_plugins]
section enables or disables the SQL Error Log Plugin. In this case, we are enabling the plugin by setting thesql_error_log
variable to 1.
Additional notes:
- You can also use command-line options to modify MariaDB system variables. For example, to set the error log file to
/var/log/mariadb/error.log
, you would run the following command:
sudo mysql --log-error=/var/log/mariadb/error.log
I hope this helps! Let me know if you have any other questions.
Using the mysqld_safe command
sudo mysqld_safe --log-error=/var/log/mariadb/error.log
Using the SET GLOBAL statement
SET GLOBAL sql_err_log_level=4;
Using a dynamic configuration file
MariaDB supports dynamic configuration files, which can be used to modify system variables without restarting the server. To use a dynamic configuration file, create a file named /etc/mysql/mariadb.cnf
and add the following lines:
[log]
log-error=/var/log/mariadb/error.log
[log_error]
sql_err_log_level=4
sql_err_log_verbosity=3
[error_log_plugins]
sql_error_log=1
Then, save the file and reload the configuration:
sudo systemctl reload mariadb
Which method should I use?
The best method for modifying MariaDB system variables will depend on your specific needs. If you only need to make a few changes, then using the mysqld_safe
command or the SET GLOBAL
statement is a good option. If you need to make more frequent changes, then using a dynamic configuration file is a better option.
Here is a table that summarizes the pros and cons of each method:
Method | Pros | Cons |
---|---|---|
mysqld_safe command | Easy to use | Requires restarting the server |
SET GLOBAL statement | Can be used without restarting the server | Changes are not permanent |
Dynamic configuration file | Changes are permanent | Requires more configuration |
mariadb