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


当前回答

Mac OS X Mavericks的当前MySQL包(在撰写本文时为MySQL -5.6.17-osx10.7-x86_64)在安装期间自动创建my.cnf。

它位于/usr/local/mysql-5.6.17-osx10.7-x86_64/my.cnf 根据您的版本调整路径。

其他回答

您可以打开一个终端并键入locate my.cnf

MySQL论坛上的这个帖子说:

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

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

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

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

通常,在Unix和类Unix系统上,MySQL/MariaDB程序在以下位置读取配置/启动文件(按指定顺序):

/etc/my.cnf - Global /etc/mysql/my.cnf - Global SYSCONFDIR/my.cnf - Global SYSCONFDIR represents the directory specified with the SYSCONFDIR option to CMake when MySQL was built. By default, this is the etc directory located under the compiled-in installation directory. $MYSQL_HOME/my.cnf - Server-specific (server only) MYSQL_HOME is an environment variable containing the path to the directory in which the server-specific my.cnf file resides. If MYSQL_HOME is not set and you start the server using the mysqld_safe program, mysqld_safe sets it to BASEDIR, the MySQL base installation directory. file specified with --defaults-extra-file=path if any ~/.my.cnf - User-specific ~/.mylogin.cnf - User-specific (clients only)

来源:使用选项文件。

注意:在Unix平台上,MySQL忽略全局可写的配置文件。这是有意为之的安全措施。


此外,在Mac上有一个简单的方法来检查它。

执行命令sudo fs_usage | grep my.cnf 这将实时报告与该文件相关的任何文件系统活动。 在另一个终端,重新启动MySQL/MariaDB,例如: 重启mysql 或者: Brew服务重新启动mariadb 在终端上使用fs_usage,应该显示正确的位置,例如。 15:52:22 access /usr/local/Cellar/mariadb/10.1.14/my.cnf 0.000002 sh 因此,如果该文件不存在,就创建一个。

阅读文档!

您所使用的版本的MySQL文档将有所帮助。 它通常被描述为选项文件或MySQL配置文件。 文档中有这些文件的位置,以及其他重要信息,如位置和配置文件必须看起来像什么小例子。

MySQL版本8

MySQL 5.7版本

MySQL 5.6版本

MySQL 5.5版本

MySQL 5.6日文

重要提示:

在Unix平台上,MySQL忽略全局可写的配置文件。 这是有意为之的安全措施。

换句话说,如果你在配置文件上设置了错误的权限,就不会加载。

一个配置文件的初始设置权限示例:

RIZZOMBP$ ls -lah /etc/my.cnf
-rw-r--r--  1 myusername  wheel     0B Feb 25 20:40 /etc/my.cnf

注意:

可以在选项文件中使用!include指令来包含其他选项文件,并使用!includedir来搜索特定目录中的选项文件..... ...MySQL不保证目录中选项文件被读取的顺序… 在Unix操作系统上使用!includedir指令找到并包含的任何文件的文件名必须以.cnf结尾。在Windows上,这个指令检查扩展名为.ini或.cnf的文件。

如何找到你的配置或日志文件等位置的例子:

SQL

这将不会显示配置文件,但将帮助您定位安装文件/文件夹。

MySQL版本5.7 & 8+

SELECT * FROM PERFORMANCE_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_VALUE LIKE '%\/%';

MySQL版本<= 5.6

SELECT * FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES WHERE VARIABLE_VALUE LIKE '%\/%';

壳牌公司-终端

RIZZOMBP$ mysql --help | grep "Default options" -A 1

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

以上命令归功于:Erwin Mayer来自ServerFault

RIZZOMBP$ mysqld --verbose --help | grep '/my.cnf' -B 1

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

OR

RIZZOMBP$ ps aux | grep -i mysqld | grep -v $USER

_mysql 106 0.4 2.5 4232336 422112 ?? Ss 7:01PM 0:57.12
/usr/local/mysql/bin/mysqld
--user=_mysql
--basedir=/usr/local/mysql
--datadir=/usr/local/mysql/data
--plugin-dir=/usr/local/mysql/lib/plugin
--log-error=/usr/local/mysql/data/mysqld.local.err
--pid-file=/usr/local/mysql/data/mysqld.local.pid
--keyring-file-data=/usr/local/mysql/keyring/keyring
--early-plugin-load=keyring_file=keyring_file.so

示例文件

如果您需要详细的参考样本my.cnf:

https://gist.github.com/search?utf8=%E2%9C%93&q=my.cnf+mysql&ref=searchresults https://www.linode.com/community/questions/5749/mysql-sample-config-files https://www.fromdual.com/mysql-configuration-file-sample

没有归属/关联的URL

我的系统:

RIZZOMBP$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.14.3
BuildVersion:   18D109
RIZZOMBP$ mysql -V
mysql  Ver 8.0.15 for macos10.14 on x86_64 (MySQL Community Server - GPL)
RIZZOMBP$ mysqld -V
/usr/local/mysql-8.0.15-macos10.14-x86_64/bin/mysqld 
Ver 8.0.15 for macos10.14 on x86_64 (MySQL Community Server - GPL)

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