![MariaDB log_error系统变量,Ubuntu 20.04和22.04之间的配置文件区别](https://linux22.com/image/1196303/MariaDB%20log_error%E7%B3%BB%E7%BB%9F%E5%8F%98%E9%87%8F%EF%BC%8CUbuntu%2020.04%E5%92%8C22.04%E4%B9%8B%E9%97%B4%E7%9A%84%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E5%8C%BA%E5%88%AB.png)
Ubuntu 20.04(焦点窝)
# dpkg -l | grep mariadb-server-10
ii mariadb-server-10.3 1:10.3.38-0ubuntu0.20.04.1 amd64 MariaDB database server binaries
# grep -E 'skip_log_error|syslog|log_error' /etc/mysql/ -R | grep -v '#'
/etc/mysql/mariadb.conf.d/50-server.cnf:log_error = /var/log/mysql/error.log
/etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf:skip_log_error
/etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf:syslog
# tail -2 /var/log/mysql/error.log
2023-07-28 8:30:23 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.3.38-MariaDB-0ubuntu0.20.04.1' socket: '/run/mysqld/mysqld.sock' port: 3306 Ubuntu 20.04
Ubuntu 22.04(Jammy Jellyfish)
# dpkg -l | grep mariadb-server-10
ii mariadb-server-10.6 1:10.6.12-0ubuntu0.22.04.1
# grep -E 'skip_log_error|syslog|log_error' /etc/mysql/ -R | grep -v '#'
/etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf:skip_log_error
/etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf:syslog
# tail -2 /var/log/mysql/error.log
tail: cannot open '/var/log/mysql/error.log' for reading: No such file or directory
直到 Ubuntu 22.04,MariaDB 日志才被写入/var/log/mysql/error.log
。由于log_error
系统变量显然已从 Ubuntu 22.04 中删除/etc/mysql/mariadb.conf.d/50-server.cnf
,因此情况不再如此。
- 为什么
log_error
从配置文件中删除/etc/mysql/mariadb.conf.d/50-server.cnf
? /var/log/mysql/error.log
为什么尽管skip_log_error
默认使用 日志文件,但在 Ubuntu 20.04 中仍会创建?- 我认为这是由于配置文件的处理顺序造成的,如果是这样,我在哪里可以看到它?
附注:
在安装 MariaDB 之前日志文件并不存在。
# ls /var/log/mysql/error.log
ls: cannot access '/var/log/mysql/error.log': No such file or directory
# dpkg -l | grep mariadb-server-10
# apt install mariadb-server
(...)
# dpkg -l | grep mariadb-server-10
ii mariadb-server-10.3 1:10.3.38-0ubuntu0.20.04.1 amd64 MariaDB database server binaries
# ls /var/log/mysql/error.log
/var/log/mysql/error.log
答案1
你确定以前没有设置过log_error吗?
在 mariadb 中选择变量查看其值:
select @@log_error
我记得自从使用 systemd 以来,log_error 就默认为无值,因此错误日志被写入 STDOUT/STDERR,以便 systemd 可以捕获它。
您仍然可以使用 journalctl 读取日志数据:
journalctl -u mariadb.service
编辑:查看该文件,可以忽略它:
$ cat /etc/mysql/mariadb.conf.d/50-mysqld_safe.cnf
# NOTE: THIS FILE IS READ ONLY BY THE TRADITIONAL SYSV INIT SCRIPT, NOT SYSTEMD.
# MARIADB SYSTEMD DOES _NOT_ UTILIZE MYSQLD_SAFE NOR READ THIS FILE.
#
# For similar behavior, systemd users should create the following file:
# /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
#
# To achieve the same result as the default 50-mysqld_safe.cnf, please create
# /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf
# with the following contents:
# [Service]
# User = mysql
# StandardOutput = syslog
# StandardError = syslog
# SyslogFacility = daemon
# SyslogLevel = err
# SyslogIdentifier = mysqld
#
# For more information, please read https://mariadb.com/kb/en/mariadb/systemd/
答案2
log_error
MariaDB 在此处删除了系统变量:https://salsa.debian.org/mariadb-team/mariadb-server/-/commit/bb8477778b72f047437b2a03a2bd38997e155f10#d3b22343b539ed028e5c8bf973b769b861541893_63_62
尽管skip_log_error
已配置,日志记录在 Ubuntu 20.04 中仍然有效的原因在于文件顺序。