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


当前回答

In my case, the file did not exist. In MySQL Workbench I went to OPTIONS FILE and found some default values. I clicked apply. It asked for permission. It then created the my.cnf file under /etc. However, it is very important to keep in mind that the first time you click "apply", you do not make any changes to the default configuration. Once the file has been created, you can make changes which will be applied when you click "apply". Otherwise you will not be shown the apply button when you make changes.

其他回答

我不知道你使用的是哪个版本的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

将/usr/local/opt/mysql/support-files/my-default.cnf复制为/etc/my.cnf或/etc/mysql/my.cnf,然后重启mysql。

MySQL论坛上的这个帖子说:

默认情况下,OS X安装不使用my.cnf, MySQL只使用默认值。要设置你自己的my.cnf,你可以直接在/etc中创建一个文件。

OS X在/usr/local/mysql/support-files/目录下提供了配置文件示例。

如果你在那里找不到它们,MySQLWorkbench可以为你创建它们:

打开连接 在菜单中选择“实例”下的“选项文件”。 MySQLWorkbench将搜索my.cnf,如果找不到它,它将为您创建它

如果你使用的是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。

在mysql 5.6.22中,my.cnf的路径为

/usr/local/opt/mysql/my.cnf