10

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
  • 133
  • 1
  • 1
  • 10
  • 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

4 Answers4

16

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
  • 538,548
  • 86
  • 673
  • 828
2

In my case the group is [mysql]

So just put [mysql] at the beginning.

joydeba
  • 778
  • 1
  • 9
  • 24
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,616
  • 9
  • 25
  • 36
Mahan Lamei
  • 29
  • 1
  • 4
0

Beside the accepted answer - which is correct - another reason for this error is that the my.ini file has been saved with encoding UTF8 +BOM (I had to set some options using MySQL Workbench).

You may need to check that Your my.ini is saved in UTF8 without BOM (or ANSI, whatever you want).


CREDITS: MySQL won’t start [ERROR] Found option without preceding group in config file

deblocker
  • 7,629
  • 2
  • 24
  • 59