Unable to enable logs in MySQL - error : Found option without preceding group in config file

Unable to enable logs in MySQL - error : Found option without preceding group in config file

我正在尝试在我的 MySQL 服务器上启用日志,但没有成功。 我做了什么:

1) 我已经创建了具有正确权限的日志文件:

touch /var/log/mysql/mysql.log   
chown mysql:mysql /var/log/mysql/mysql.log

2) 我已将所需的更改添加到 my.cnf 文件中:

general_log_file        = /var/log/mysql/mysql.log
general_log             = 1

我的 my.cnf 文件如下:

#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.
#

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

general_log_file        = /var/log/mysql/mysql.log
general_log             = 1

我无法重新启动 MySQL,当我尝试登录时,出现此错误:

error: Found option without preceding group in config file: /etc/mysql/my.cnf at line: 23 Fatal error in defaults handling. Program aborted

这是什么意思,我该如何解决?

我正在使用 Ubuntu 15.05MySQL 5.6.24-0ubuntu2

打开my.conf,找到[mysqld],在那个下面写下服务器变量。

log = /var/log/mysqld.log
log-error = /var/log/mysqld.error.log

确保文件有644或以上权限。使用

查找 mysql 错误日志变量

显示像“%log%”这样的变量;

最新 mysql 正在使用 log、log-error 变量。

谢谢 阿米特

也许您应该将 [mysqld] 添加为 my.cnf 文件的第一行。

在我的例子中,我正确设置了 [mysqld] 部分,但这个错误是由文件开头的 无效空白字符 引起的。它导致解析文件失败。在从 windows 到 linux 的 copying/uploading 期间,以某种方式将字符插入到那里。我需要通过 linux 文件查看器打开文件,然后删除无效字符,然后它工作正常。