简体   繁体   English

如何修复:mysql:[错误] 在配置文件 /etc/mysql/my.cnf 中找到没有前面组的选项?

[英]How to fix: mysql: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf?

I am getting the following error when trying to access mysql:尝试访问 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. mysql:[错误] 在配置文件 /etc/mysql/my.cnf 的第 22 行找到没有前面组的选项:mysql。[错误] 默认处理中的致命错误。 Program aborted!程序中止!

/etc/mysql/my.cnf /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.任何帮助,将不胜感激。

All options in your my.cnf need to be within a "group" like: my.cnf 中的所有选项都需要在一个“组”中,例如:

[mysqld]
bind-address 127.0.0.1

The group in this example is "mysqld".本例中的组是“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.阅读https://dev.mysql.com/doc/refman/5.7/en/option-files.html有关如何格式化 MySQL 选项文件的更多详细信息。

In my case the group is [mysql]在我的情况下,该组是 [mysql]

So just put [mysql] at the beginning.所以只需将[mysql]放在开头。

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.我认为与 MySQL 期望的相比,在 Windows 中保存文件存在 LF - CR/LF 差异。

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).除了已接受的答案(这是正确的)之外,此错误的另一个原因是 my.ini 文件已使用 UTF8 +BOM 编码保存(我必须使用 MySQL Workbench 设置一些选项)。

You may need to check that Your my.ini is saved in UTF8 without BOM (or ANSI, whatever you want).您可能需要检查您的 my.ini 是否保存为没有 BOM的 UTF8(或 ANSI,无论您想要什么)。


CREDITS: MySQL won't start [ERROR] Found option without preceding group in config file学分: MySQL 不会启动 [错误] 在配置文件中找到没有前面组的选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM