【问题标题】:Mariadb configuration is not loaded from my.cnfMariadb 配置未从 my.cnf 加载
【发布时间】:2026-01-23 00:15:02
【问题描述】:

我在 my.cnf 中的 mariadb 配置没有为 "log-error""pid-file" 加载。我已经检查了其他配置参数是否已加载。

[root@kvm10 ~]# cat /etc/my.cnf
[mysqld]
!includedir /etc/mysqld/conf.d
datadir=/mnt/mgmt/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
tmpdir=/mnt/mgmt/var/lib/mysql_tmp
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
### TRT-3229 #####
sync_binlog=1
innodb_flush_method=O_DIRECT
innodb_support_xa = 1
myisam_repair_threads = 2
myisam_recover_options = FORCE
###################
innodb_file_per_table=1
innodb_log_buffer_size = 8M
table_open_cache=256
max_heap_table_size=256M
### TRT-4685 ###
max_connections=500
################
innodb_log_file_size = 512M

[mysqld_safe]
log-error=/var/log/mariadb/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
[root@kvm10 ~]# 

log-errorpid-file 的配置值不是 MariaDB 选择的。

[root@kvm10 ~]# mysql -e "show variables like 'pid_file'"
+---------------+-----------------------------------+
| Variable_name | Value                             |
+---------------+-----------------------------------+
| pid_file      | /mnt/mgmt/var/lib/mysql/kvm10.pid |
+---------------+-----------------------------------+
[root@kvm10 ~]# mysql -e "show variables like 'log_error'"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_error     |       |
+---------------+-------+
[root@kvm10 ~]# 

我是错过了什么还是犯了一些错误。我已经检查了/var/log/mariadb/mysqld.log/var/run/mysqld/mysqld.pid 中的文件权限。

【问题讨论】:

  • 这个问题与软件开发无关,DBA 可以在 dba.stackexchange.com 姐妹网站上回答这个问题。

标签: mysql mariadb my.cnf


【解决方案1】:

如果您通过运行mysqld_safe 直接或通过旧式初始化脚本(MariaDB 5.5/10.0 或更旧的 Linux 发行版)运行服务器,则应该从配置文件中选择这些选项。如果您有 MariaDB 10.1+ 和支持 systemd 的 Linux 发行版并通过该服务启动 MariaDB 服务器,则不使用 mysqld_safe

它们可能不起作用的另一个原因是,如果您在没有 --defaults-file 选项的情况下启动 mysqld_safe,并且默认位置的其他位置有另一个配置文件覆盖了这些选项。

1) 将选项添加到配置文件的[mysqld] 部分,重新​​启动服务器并查看是否有帮助。

如果没有帮助,

2a) 如果你通过systemd服务运行MariaDB服务器,检查服务配置,可能里面有东西;

2b) 如果您通过mysqld_safe 运行MariaDB 服务器,请尝试使用--defaults-file=/etc/my.cnf 启动它,以确保仅使用此配置文件。

【讨论】: