MySQL my.cnf 文件 - 找到没有前面组的选项

发布于 2024-12-14 03:23:19 字数 914 浏览 4 评论 0原文

我正在尝试远程连接到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

忆沫 2024-12-21 03:23:19

缺少配置标头

只需将 [mysqld] 添加为 /etc/mysql/my.cnf 文件中的第一行。

示例

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

之后,请记住重新启动 MySQL 服务。

sudo mysqld stop
sudo mysqld start

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
深海夜未眠 2024-12-21 03:23:19

字符集编码

检查文件的字符集编码。确保它是 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.

你是年少的欢喜 2024-12-21 03:23:19

对我有用的:

  • 使用 Notepad++ Encoding 打开 my.ini
  • -->转换为 ANSI
  • 保存

What worked for me:

  • Open my.ini with Notepad++
  • Encoding --> convert to ANSI
  • save
私藏温柔 2024-12-21 03:23:19

这是因为[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

木有鱼丸 2024-12-21 03:23:19

我在使用社区安装程序安装 MySQL 8.0.15 时遇到了这个问题。安装程序附带的 my.ini 文件在编辑后无法正常工作。我通过下载该 zip 文件夹进行了完整的手动安装。我能够创建自己的 my.ini 文件,仅包含我关心的参数并且它有效。

  1. 从 MySQL 网站下载 zip 文件,
  2. 将文件夹解压到
  3. 您将 zip 文件夹解压到的 MySQL8.0 文件夹中的 C:\program files\MySQL\MySQL8.0 中,创建一个文本文件并将其另存为 my.ini
  4. include您关心的 my.ini 文件中的参数。所以像这样(只要确保已经为 datadir 创建了一个文件夹,否则初始化将无法工作):

    <前><代码>[mysqld]
    basedire=C:\program files\MySQL\MySQL8.0
    datadir=D:\MySQL\数据
    ....继续使用您想要包含的任何参数

  5. 通过在命令提示符中运行这两个命令来初始化数据目录:

    cd C:\program files\MySQL\MySQL8.0\bin
    mysqld --default-file=C:\program files\MySQL\MySQL8.0\my.ini --initialize
    
  6. 通过运行这两个命令将 MySQL 服务器安装为服务:

    cd C:\program files\MySQL\MySQL8.0\bin
    mysqld --install --default-file=C:\program files\MySQL\MySQL8.0\my.ini
    
  7. 最后,通过运行这两个命令首次启动服务器:

    cd C:\program files\MySQL\MySQL8.0\bin
    mysqld --控制台
    

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
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文