MySQL my.cnf file - Found option without preceding group
Asked Answered
C

5

91

I'm trying to connect to my DB in Ubuntu remotely but I receive error message when trying to mysql -u root -p:

Found option without preceding group in config file: /etc/mysql/my.cnf at line: 1

my.cnf looks like:

[mysqld]
user        = mysql
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
bind-address        =  0.0.0.0
key_buffer      = 16M
max_allowed_packet  = 16M
thread_stack        = 192K
thread_cache_size       = 8
myisam-recover         = BACKUP
query_cache_limit   = 1M
query_cache_size        = 16M
log_error                = /var/log/mysql/error.log
expire_logs_days    = 10
max_binlog_size         = 100M

[client]
port        = 3306
socket      = /var/run/mysqld/mysqld.sock

[mysqld_safe]
socket      = /var/run/mysqld/mysqld.sock
nice        = 0

[mysqldump]
quick
quote-names
max_allowed_packet  = 16M

[mysql]

[isamchk]
key_buffer      = 16M
Cartouche answered 5/11, 2011 at 12:56 Comment(4)
This looks pretty different from the default my.cnf which is installed with mysql on Ubuntu. Have you tried starting from the default file and gradually adding in your customizations?Secant
I just removed comments and moved around the codeCartouche
I think the default file looks a little different.Hemingway
Is this kind of setup version specific? I'm running into the same problem on Ubuntu 16 and mysql 5.7 or something like that... fresh install from apt.Totalizer
O
66

Charset encoding

Check the charset encoding of the file. Make sure that it is in ASCII.

Use the od command to see if there is a UTF-8 BOM at the beginning, for example.

Ossify answered 5/11, 2011 at 13:1 Comment(3)
Additional note: Lack of [mysqld] causes the error too.Stocker
For some reason [mysqld] was missing from the beginning of my my.cnf. Adding it there solved the issue, mysql running as expected now.Diazomethane
This was my issue after editing the file with MySQL workbench on Windows. I solved it by opening it in WordPad and saving it as a "Plain Text Document"Isocracy
S
136

Missing config header

Just add [mysqld] as first line in the /etc/mysql/my.cnf file.

Example

[mysqld]
default-time-zone = "+08:00"

Afterwards, remember to restart your MySQL Service.

sudo mysqld stop
sudo mysqld start
Suffragist answered 17/4, 2017 at 12:2 Comment(1)
His my.cnf already has [mysqld]... your answer is useful for those who don't have that line.Unrequited
O
66

Charset encoding

Check the charset encoding of the file. Make sure that it is in ASCII.

Use the od command to see if there is a UTF-8 BOM at the beginning, for example.

Ossify answered 5/11, 2011 at 13:1 Comment(3)
Additional note: Lack of [mysqld] causes the error too.Stocker
For some reason [mysqld] was missing from the beginning of my my.cnf. Adding it there solved the issue, mysql running as expected now.Diazomethane
This was my issue after editing the file with MySQL workbench on Windows. I solved it by opening it in WordPad and saving it as a "Plain Text Document"Isocracy
P
16

What worked for me:

  • Open my.ini with Notepad++
  • Encoding --> convert to ANSI
  • save
Pinko answered 13/1, 2020 at 18:32 Comment(0)
C
13

it is because of letters or digit infront of [mysqld] just check the leeters or digit anything is not required before [mysqld]

it may be something like

0[mysqld] then this error will occur

Crofter answered 21/10, 2012 at 14:25 Comment(2)
yes there was a random + character in the configuration file. Thanks!Mealtime
For me it ended up being a comment at the beginning of the file that didn't have a # before it to start the commenting procedure!Explosion
C
0

I had this problem when I installed MySQL 8.0.15 with the community installer. The my.ini file that came with the installer did not work correctly after it had been edited. I did a full manual install by downloading that zip folder. I was able to create my own my.ini file containing only the parameters that I was concerned about and it worked.

  1. download zip file from MySQL website
  2. unpack the folder into C:\program files\MySQL\MySQL8.0
  3. within the MySQL8.0 folder that you unpacked the zip folder into, create a text file and save it as my.ini
  4. include the parameters in that my.ini file that you are concerned about. so something like this(just ensure that there is already a folder created for the datadir or else initialization won't work):

    [mysqld]
    basedire=C:\program files\MySQL\MySQL8.0
    datadir=D:\MySQL\Data
    ....continue with whatever parameters you want to include
    
  5. initialize the data directory by running these two commands in the command prompt:

    cd C:\program files\MySQL\MySQL8.0\bin
    mysqld --default-file=C:\program files\MySQL\MySQL8.0\my.ini --initialize
    
  6. install the MySQL server as a service by running these two commands:

    cd C:\program files\MySQL\MySQL8.0\bin
    mysqld --install --default-file=C:\program files\MySQL\MySQL8.0\my.ini
    
  7. finally, start the server for the first time by running these two commands:

    cd C:\program files\MySQL\MySQL8.0\bin
    mysqld --console
    
Coeternity answered 12/4, 2019 at 21:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.