9

I am getting the following error when trying to access mysql:

mysql: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf at line 22! mysql: [ERROR] Fatal error in defaults handling. Program aborted!

/etc/mysql/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/
bind-address = 127.0.0.1
general_log_file = /var/log/mysql/mysql.log
general_log = 1

Any help would be appreciated.

Ryan
  • 123
  • 1
  • 1
  • 8
  • Line 22 is your bind address. The question - since I have it too - is what preceding group are they talking about? – Malik A. Rumi Jul 17 '17 at 19:05
  • I faced same issue when by mistake I replaced #The MySQL database server configuration file. line with some characters without # in front of those. – Mukesh Jun 17 '19 at 13:08
  • 1
    Possible duplicate of [MySQL my.cnf file - Found option without preceding group](https://stackoverflow.com/questions/8020297/mysql-my-cnf-file-found-option-without-preceding-group) – colan Jun 20 '19 at 15:15

3 Answers3

15

All options in your my.cnf need to be within a "group" like:

[mysqld]
bind-address 127.0.0.1

The group in this example is "mysqld". The group is named by a line preceding the options, and the name of the group is in square brackets.

Your file doesn't have any group identifier named before you start giving options.

Read https://dev.mysql.com/doc/refman/5.7/en/option-files.html for more details on how to format MySQL option files.

Bill Karwin
  • 499,602
  • 82
  • 638
  • 795
2

In my case the group is [mysql]

So just put [mysql] at the beginning.

joydeba
  • 490
  • 1
  • 6
  • 18
0

I removed every comment (lines starting with # ) from the beginning of the file. It worked. I just moved the comments to the end of the file for the record.

I think there is a LF - CR/LF difference in saving the file in windows comparing to what MySQL expects.

kenlukas
  • 3,221
  • 9
  • 23
  • 35
Mahan Lamei
  • 31
  • 1
  • 4