9

我正在尝试在我的 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,当我尝试记录时,出现此错误:

错误:在配置文件中找到没有前组的选项:/etc/mysql/my.cnf 在行:23 默认处理中的致命错误。程序中止

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

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

4

3 回答 3

24

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

于 2015-07-10T12:01:29.023 回答
0

就我而言,我正确设置了 [mysqld] 部分,但此错误是由文件开头的无效空白字符引起的。它导致解析文件失败。在从 Windows 复制/上传到 linux 期间以某种方式插入了字符。我需要通过 linux 文件查看器打开文件,然后删除无效字符,然后它工作正常。

于 2016-09-05T08:22:27.263 回答
0

打开 my.conf,在下面找到[mysqld]写入服务器变量,如下所述。

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

确保该文件具有 644 或以上权限。使用查找 mysql 错误日志变量

显示变量,如“%log%”;

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

谢谢阿米特

于 2015-07-10T12:01:12.087 回答