You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 20.04与22.04中MariaDB log_error系统变量及配置差异的技术咨询

Ubuntu 20.04与22.04中MariaDB log_error系统变量及配置差异的技术咨询

环境信息对比

Ubuntu 20.04 (Focal Fossa)

已安装的MariaDB版本:

# 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)

已安装的MariaDB版本:

# 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

问题解答

1. 为什么Ubuntu 22.04中log_error从/etc/mysql/mariadb.conf.d/50-server.cnf里被移除了?

这主要和Ubuntu打包MariaDB的策略以及版本特性变化有关。在Ubuntu 22.04搭配的MariaDB 10.6版本中,官方调整了默认日志行为:当syslog(默认在50-mysqld_safe.cnf中启用)开启时,系统会优先将错误日志发送到syslog服务,不再默认配置单独的文件日志路径。

另外,MariaDB 10.6对日志配置优先级做了优化——当skip_log_error和syslog同时启用时,会直接跳过文件日志输出。Ubuntu打包团队考虑到这一点,就移除了log_error的默认配置,避免出现配置冲突或无效配置的情况。

2. 为什么Ubuntu 20.04中默认启用了skip_log_error,但/var/log/mysql/error.log还是被创建了?

核心原因是配置的作用对象和加载优先级差异:

  • log_error是mysqld(数据库服务进程)本身的系统变量,配置在50-server.cnf中,这个文件是mysqld的核心配置,加载优先级很高;
  • skip_log_error是mysqld_safe(启动mysqld的脚本)的选项,配置在50-mysqld_safe.cnf中。

在Ubuntu 20.04的MariaDB 10.3环境中,mysqld会优先读取自身配置里的log_error参数,即使mysqld_safe传递了--skip-log-error参数,也会被log_error的显式配置覆盖。所以服务启动时会按照指定路径创建日志文件,并且正常写入日志内容。

3. 如果是配置加载顺序导致的,在哪里可以查看这个顺序?

你可以通过两种方式确认:

  • 查看默认配置加载顺序:执行以下命令,会输出mysqld读取配置文件的默认顺序:
    mysqld --verbose --help | grep -A 10 "Default options"
    
    输出类似:
    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
    
    而/etc/mysql/mariadb.conf.d/下的配置文件,会按文件名的数字排序加载(比如50-server.cnf会在后续同目录的非数字前缀文件之前加载)。
  • 查看最终生效的配置:执行以下命令,能看到所有最终生效的配置参数,从中可以判断哪些配置被优先应用:
    mysqld --print-defaults
    

补充说明

在安装MariaDB之前,目标日志文件并不存在:

# ls /var/log/mysql/error.log
ls: cannot access '/var/log/mysql/error.log': No such file or directory

完成MariaDB安装后,日志文件会被自动创建:

# 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

备注:内容来源于stack exchange,提问作者obeN

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 09:28:06