我试图按照本教程来启用远程访问MySQL。问题是,my.cnf文件应该放在哪里?我使用的是Mac OS X Lion。


当前回答

如果你使用的是macOS Sierra,而该文件不存在, 运行

Mysql——help或Mysql——help | grep my.cnf

要查看mysql my.cnf的可能位置和加载/读取顺序,请在建议的目录之一中创建my.cnf文件,然后添加以下行

[mysqld] sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

您可以sudo触摸/{首选路径}/my.cnf,然后编辑文件添加sql模式by

Sudo nano /{首选路径}/my.cnf

然后重新启动MySQL。

其他回答

这些东西对我都没用。我正在使用当前的dmg安装mysql社区服务器。ps显示my.cnf中所有最关键的参数通常都是在命令行上传递的,我不知道这是从哪里来的。在对我的盒子进行全文搜索后,我发现它在:

/ Library / LaunchDaemons / com . oracle, mysql oss。mysqld plist。

你可以在这里修改它们,也可以把它们拿出来这样它就会尊重你在my。cnf里的那些,不管你放在哪里。

享受吧!

在该文件中找到的文件信息示例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>             <string>com.oracle.oss.mysql.mysqld</string>
    <key>ProcessType</key>       <string>Interactive</string>
    <key>Disabled</key>          <false/>
    <key>RunAtLoad</key>         <true/>
    <key>KeepAlive</key>         <true/>
    <key>SessionCreate</key>     <true/>
    <key>LaunchOnlyOnce</key>    <false/>
    <key>UserName</key>          <string>_mysql</string>
    <key>GroupName</key>         <string>_mysql</string>
    <key>ExitTimeOut</key>       <integer>600</integer>
    <key>Program</key>           <string>/usr/local/mysql/bin/mysqld</string>
    <key>ProgramArguments</key>
        <array>
            <string>/usr/local/mysql/bin/mysqld</string>
            <string>--user=_mysql</string>
            <string>--basedir=/usr/local/mysql</string>
            <string>--datadir=/usr/local/mysql/data</string>
            <string>--plugin-dir=/usr/local/mysql/lib/plugin</string>
            <string>--log-error=/usr/local/mysql/data/mysqld.local.err</string>
            <string>--pid-file=/usr/local/mysql/data/mysqld.local.pid</string>
             <string>--keyring-file-data=/usr/local/mysql/keyring/keyring</string>
             <string>--early-plugin-load=keyring_file=keyring_file.so</string>

        </array>
    <key>WorkingDirectory</key>  <string>/usr/local/mysql</string>
</dict>
</plist>

MySQL 5.7.18版本后,在support-files目录下不再提供默认配置文件。 因此,您可以在MySQL读取的位置手动创建my.cnf文件,例如/etc/mysql/my.cnf,并在该文件中添加您想要添加的配置。

/private/etc/my.cnf for Catalina

如果在Mac M1和MacOS Monterey 12.0.1中使用Homebrew安装MySQL,则位置为/opt/ Homebrew /etc/my.cnf

我不知道你使用的是哪个版本的MySQL,但以下是Mac OS X 5.5版本my.cnf文件的可能位置(从这里取):

/etc/my.cnf /etc/mysql/my.cnf SYSCONFDIR / my.cnf $ MYSQL_HOME / my.cnf Defaults-extra-file(使用——Defaults-extra-file =path指定的文件,如果有的话) ~ / .my.cnf