9

I am trying to enable logs on my MySQL server but with no success. What I have done :

1) I have created the log file with the right permissions :

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

2) I have added the needed change to the my.cnf file :

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

My my.cnf file is the following :

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

I am unable to restart MySQL and when I try to logging, I have this error :

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

What does that mean and how I can fix this ?

I am using Ubuntu 15.05 with MySQL 5.6.24-0ubuntu2

hg8
  • 1,082
  • 2
  • 15
  • 28

3 Answers3

24

Perhaps you should add [mysqld] as a first line of your my.cnf file.

juanra
  • 1,602
  • 19
  • 17
  • 1
    This worked for me as well, but unfortunately the answer doesn't explain the why. – armadadrive Jan 14 '17 at 16:25
  • 1
    @armadadrive You are right. The why is related to the error message: "Found option without preceding group in config file". The [mysqld] tag is the way to declare the group (the name of the program) for which you want to set options. – juanra Jan 15 '17 at 17:49
  • This saved me. But why didn't mysql include [mysqld] in my.cnf file – Olakunle Awotunbo Mar 30 '17 at 09:52
0

Open my.conf, look for [mysqld] under that write the server variable as mentioned below.

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

Make sure the file has 644 or above permission. Look for mysql error log variable using

show variables like '%log%';

Latest mysql is using log, log-error variables.

Thanks Amit

Amit Shah
  • 1,380
  • 1
  • 10
  • 19
0

In my case I had the section [mysqld] correctly set, but this error was caused by invalid whitespace character at the begin of the file. It caused failure in parsing the file. Character was inserted there somehow during copying/uploading from windows to linux. I needed to open file by linux file viewer and then delete invalid character and then it worked fine.

lubosdz
  • 4,210
  • 2
  • 29
  • 43