[英]How to fix: mysql: [ERROR] Found option without preceding group in config file /etc/mysql/my.cnf?
尝试访问 mysql 时出现以下错误:
mysql:[错误] 在配置文件 /etc/mysql/my.cnf 的第 22 行找到没有前面组的选项:mysql。[错误] 默认处理中的致命错误。 程序中止!
/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
任何帮助,将不胜感激。
my.cnf 中的所有选项都需要在一个“组”中,例如:
[mysqld]
bind-address 127.0.0.1
本例中的组是“mysqld”。 该组由选项前的一行命名,组名在方括号中。
在您开始提供选项之前,您的文件没有任何命名的组标识符。
阅读https://dev.mysql.com/doc/refman/5.7/en/option-files.html有关如何格式化 MySQL 选项文件的更多详细信息。
在我的情况下,该组是 [mysql]
所以只需将[mysql]
放在开头。
我从文件的开头删除了所有注释(以 # 开头的行)。 有效。 我只是将评论移到文件末尾以供记录。
我认为与 MySQL 期望的相比,在 Windows 中保存文件存在 LF - CR/LF 差异。
除了已接受的答案(这是正确的)之外,此错误的另一个原因是 my.ini 文件已使用 UTF8 +BOM 编码保存(我必须使用 MySQL Workbench 设置一些选项)。
您可能需要检查您的 my.ini 是否保存为没有 BOM的 UTF8(或 ANSI,无论您想要什么)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.