MySQL my.cnf 文件 - 找到没有前面组的选项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8020297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL my.cnf file - Found option without preceding group
提问by Afra
I'm trying to connect to my DB in Ubuntu remotely but I receive error message when trying to mysql -u root -p:
我正在尝试远程连接到 Ubuntu 中的数据库,但在尝试执行mysql -u root -p以下操作时收到错误消息:
Found option without preceding group in config file: /etc/mysql/my.cnf at line: 1
在配置文件中找到没有前面组的选项:/etc/mysql/my.cnf at line: 1
my.cnf looks like:
my.cnf 看起来像:
[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
采纳答案by aleroot
Charset encoding
字符集编码
Check the charset encoding of the file. Make sure that it is in ASCII.
检查文件的字符集编码。确保它是 ASCII。
Use the odcommand to see if there is a UTF-8 BOM at the beginning, for example.
例如,使用该od命令查看开头是否有UTF-8 BOM。
回答by vmishra
Missing config header
缺少配置头
Just add [mysqld]as first line in the /etc/mysql/my.cnffile.
只需添加[mysqld]为/etc/mysql/my.cnf文件中的第一行。
Example
例子
[mysqld]
default-time-zone = "+08:00"
Afterwards, remember to restart your MySQL Service.
之后,记得重启你的 MySQL 服务。
sudo mysqld stop
sudo mysqld start
回答by payal
it is because of letters or digit infront of [mysqld] just check the leeters or digit anything is not required before [mysqld]
这是因为 [mysqld] 前面的字母或数字只需检查字母或数字 [mysqld] 之前不需要任何东西
it may be something like
它可能是这样的
0[mysqld] then this error will occur
0[mysqld] 那么就会出现这个错误
回答by MJL
What worked for me:
什么对我有用:
- Open my.ini with Notepad++
- Encoding --> convert to ANSI
- save
- 用 Notepad++ 打开 my.ini
- 编码 --> 转换为 ANSI
- 节省
回答by Mitchell Leefers
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.
我在使用社区安装程序安装 MySQL 8.0.15 时遇到了这个问题。安装程序附带的 my.ini 文件在编辑后无法正常工作。我通过下载该 zip 文件夹进行了完整的手动安装。我能够创建我自己的 my.ini 文件,其中只包含我关心的参数并且它起作用了。
- download zip file from MySQL website
- unpack the folder into C:\program files\MySQL\MySQL8.0
- within the MySQL8.0 folder that you unpacked the zip folder into, create a text file and save it as my.ini
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 includeinitialize 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 --initializeinstall 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.inifinally, start the server for the first time by running these two commands:
cd C:\program files\MySQL\MySQL8.0\bin mysqld --console
- 从 MySQL 网站下载 zip 文件
- 将文件夹解压到 C:\program files\MySQL\MySQL8.0
- 在您将 zip 文件夹解压到的 MySQL8.0 文件夹中,创建一个文本文件并将其保存为 my.ini
在 my.ini 文件中包含您关心的参数。所以像这样(只需确保已经为 datadir 创建了一个文件夹,否则初始化将不起作用):
[mysqld] basedire=C:\program files\MySQL\MySQL8.0 datadir=D:\MySQL\Data ....continue with whatever parameters you want to include通过在命令提示符下运行这两个命令来初始化数据目录:
cd C:\program files\MySQL\MySQL8.0\bin mysqld --default-file=C:\program files\MySQL\MySQL8.0\my.ini --initialize通过运行以下两个命令将 MySQL 服务器安装为服务:
cd C:\program files\MySQL\MySQL8.0\bin mysqld --install --default-file=C:\program files\MySQL\MySQL8.0\my.ini最后,通过运行以下两个命令首次启动服务器:
cd C:\program files\MySQL\MySQL8.0\bin mysqld --console

