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


当前回答

你可以在任何你想要的目录下创建你的文件。创建完成后,你可以“告诉”mysql配置的路径:

其他回答

如果你使用的是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.7 on Mac OS X El Capitan: /usr/local/mysql/etc/my.cnf

从/usr/local/mysql/support-files/my-default.cnf拷贝default conf文件

MySQL论坛上的这个帖子说:

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

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

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

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

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.

对于Mac,对我有用的是在我的~路径中创建一个.my.cnf文件。希望这能有所帮助。