MySQL my.cnf 文件 - 找到没有前面组的选项
我正在尝试远程连接到 Ubuntu 中的数据库,但在尝试 mysql -u root -p 时收到错误消息:
在配置文件 /etc/mysql/my.cnf 第 1 行找到没有前面组的选项
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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
缺少配置标头
只需将
[mysqld]
添加为/etc/mysql/my.cnf
文件中的第一行。示例
之后,请记住重新启动 MySQL 服务。
Missing config header
Just add
[mysqld]
as first line in the/etc/mysql/my.cnf
file.Example
Afterwards, remember to restart your MySQL Service.
字符集编码
检查文件的字符集编码。确保它是 ASCII 格式。
例如,使用 od 命令查看开头是否有 UTF-8 BOM。
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.对我有用的:
What worked for me:
这是因为[mysqld]前面有字母或数字,只需检查[mysqld]之前不需要的字母或数字,
它可能是类似
0[mysqld]的东西,那么就会发生此错误
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
我在使用社区安装程序安装 MySQL 8.0.15 时遇到了这个问题。安装程序附带的 my.ini 文件在编辑后无法正常工作。我通过下载该 zip 文件夹进行了完整的手动安装。我能够创建自己的 my.ini 文件,仅包含我关心的参数并且它有效。
include您关心的 my.ini 文件中的参数。所以像这样(只要确保已经为 datadir 创建了一个文件夹,否则初始化将无法工作):
<前><代码>[mysqld]
basedire=C:\program files\MySQL\MySQL8.0
datadir=D:\MySQL\数据
....继续使用您想要包含的任何参数
通过在命令提示符中运行这两个命令来初始化数据目录:
通过运行这两个命令将 MySQL 服务器安装为服务:
最后,通过运行这两个命令首次启动服务器:
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.
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):
initialize the data directory by running these two commands in the command prompt:
install the MySQL server as a service by running these two commands:
finally, start the server for the first time by running these two commands: