首页 文章

对于自制的mysql安装,my.cnf在哪里?

提问于
浏览
264

对于自制的mysql安装,my.cnf在哪里?它安装一个吗?

11 回答

  • 15

    对于Homebrew,mysql也会在它的Cellar目录中查找my.cnf,例如:

    /usr/local/Cellar/mysql/5.7.21/my.cnf
    

    对于这种情况,人们更喜欢将配置保持在二进制文件附近 - 如果缺少,请在此处创建 my.cnf .

    更改后重新启动mysql:

    brew services restart mysql
    
  • 231

    默认情况下没有my.cnf . 因此,MySQL以所有默认设置启动 . 如果您想创建自己的my.cnf以覆盖任何默认值,请将其放在/etc/my.cnf .

    此外,您可以运行 mysql --help 并查看列出的配置位置 .

    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 
    The following groups are read: mysql client
    The following options may be given as the first argument:
    --print-defaults        Print the program argument list and exit.
    --no-defaults           Don't read default options from any option file.
    --defaults-file=#       Only read default options from the given file #.
    --defaults-extra-file=# Read this file after the global files are read.
    

    如您所见,还有一些选项可以绕过conf文件,或指定在命令行调用mysql时要读取的其他文件 .

  • 6

    自制软件mysql包含安装的support-files文件夹中的示例配置文件 .

    ls $(brew --prefix mysql)/support-files/my-*
    

    如果您需要更改默认设置,可以使用其中一个作为起点 .

    cp $(brew --prefix mysql)/support-files/my-default.cnf /usr/local/etc/my.cnf
    

    正如@rednaw所指出的那样,自制的MySQL安装很可能在 /usr/local 中,因此不应将my.cnf文件添加到系统 /etc 文件夹中,因此我已将命令更改为 /usr/local/etc .

    如果您使用的是MariaDB而不是MySQL,请使用以下命令:

    cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/etc/my.cnf
    
  • 24

    一种方法可以找到:

    sudo /usr/libexec/locate.updatedb
    # wait a few minutes for it to finish
    locate my.cnf
    
  • 8

    什么都没有帮助我 - 我无法覆盖/etc/my.cnf文件中的设置 . 所以我像John建议的那样搜索https://stackoverflow.com/a/7974114/717251

    sudo /usr/libexec/locate.updatedb
    # wait a few minutes for it to finish
    locate my.cnf
    

    它发现了另一个my.cnf

    /usr/local/Cellar/mysql/5.6.21/my.cnf
    

    更改此文件对我有用!不要忘记重启启动代理:

    launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
    

    更新:

    如果你有一个相当新的自制软件安装,你应该使用brew服务命令重新启动mysql(使用你安装的自制mysql版本,即mysql或mysql@5.7):

    brew services stop mysql
    brew services start mysql
    
  • 10

    在你的shell上输入 my_print_defaults --help

    在结果的底部,您应该能够看到服务器从中读取配置的文件 . 它打印的内容如下:

    Default options are read from the following files in the given order:
    /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
    
  • 4

    在我的系统中它是

    nano /usr/local/etc/my.cnf.default
    

    作为模板和

    nano /usr/local/etc/my.cnf
    

    工作 .

  • 264

    由于 mysql --help 显示了一个文件列表,我发现将结果传递给 ls 以查看它们中存在哪些文件非常有用:

    $ mysql --help | grep /my.cnf | xargs ls
    ls: /etc/my.cnf: No such file or directory
    ls: /etc/mysql/my.cnf: No such file or directory
    ls: ~/.my.cnf: No such file or directory
    /usr/local/etc/my.cnf
    

    对于我的(Homebrew安装)MySQL 5.7,似乎文件在 /usr/local/etc/my.cnf 上 .

  • 4

    我相信答案是否定的 . 在〜/ .my.cnf或/ usr / local / etc中安装一个似乎是首选的解决方案 .

  • 0

    您可以找到特定包提供 my.cnf 文件的位置,例如

    brew list mysql # or: mariadb
    

    除了验证是否已读取该文件外,您还可以运行:

    sudo fs_usage | grep my.cnf
    

    它将实时显示与该文件相关的文件系统活动 .

  • 1

    对于MacOS(High Sierra),已经安装了家庭酿造的MySQL .

    从mysql环境增加全局变量并不成功 . 所以在这种情况下创建〜/ .my.cnf是最安全的选择 . 使用[mysqld]添加变量将包括更改(注意:如果使用[mysql]更改,则更改可能不起作用) .

    <〜/ .my.cnf> [mysqld] connect_timeout = 43200 max_allowed_packet = 2048M net_buffer_length = 512M

    重启mysql服务器 . 并检查变量 . ÿ

    sql> SELECT @@ max_allowed_packet; ---------------------- | @@ max_allowed_packet | ---------------------- | 1073741824 | ----------------------

    1排(0.00秒)

相关问题