MySQL my.cnf 文件在 macOS 上的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10757169/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Location of my.cnf file on macOS
提问by nicolas
I'm trying to follow along this tutorialto enable remote access to MySQL. The problem is, where should my.cnf
file be located? I'm using Mac OS X Lion.
我正在尝试按照本教程来启用对 MySQL 的远程访问。问题是,my.cnf
文件应该放在哪里?我正在使用 Mac OS X Lion。
回答by bfavaretto
This thread on the MySQL forumsays:
By default, the OS X installation does not use a my.cnf, and MySQL just uses the default values. To set up your own my.cnf, you could just create a file straight in /etc.
默认情况下,OS X 安装不使用 my.cnf,而 MySQL 只使用默认值。要设置您自己的 my.cnf,您可以直接在 /etc 中创建一个文件。
OS X provides example configuration files at /usr/local/mysql/support-files/
.
OS X 在/usr/local/mysql/support-files/
.
And if you can't find them there, MySQLWorkbench can create them for you by:
如果您在那里找不到它们,MySQLWorkbench 可以通过以下方式为您创建它们:
- Opening a connection
- Selecting the 'Options File' under 'INSTANCE' in the menu.
- MySQLWorkbench will search for my.cnf and if it can't find it, it'll create it for you
- 打开连接
- 选择菜单中“实例”下的“选项文件”。
- MySQLWorkbench 将搜索 my.cnf,如果找不到,它会为您创建
回答by Eigengrau
In case of Mac OS X Maverick when MySQL is installed via Homebrew it's located at /usr/local/opt/mysql/my.cnf
对于 Mac OS X Maverick,当 MySQL 通过 Homebrew 安装时,它位于 /usr/local/opt/mysql/my.cnf
回答by kenorb
In general, on Unix and Unix-like systems, MySQL/MariaDB programs read config/startup files in the following locations (in the specified order):
通常,在 Unix 和类 Unix 系统上,MySQL/MariaDB 程序读取以下位置的配置/启动文件(按指定顺序):
/etc/my.cnf
- Global/etc/mysql/my.cnf
- GlobalSYSCONFDIR/my.cnf
- GlobalSYSCONFDIR
represents the directory specified with theSYSCONFDIR
option toCMake
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-specificmy.cnf
file resides. IfMYSQL_HOME
is not set and you start the server using themysqld_safe
program,mysqld_safe
sets it toBASEDIR
, the MySQL base installation directory.file specified with
--defaults-extra-file=path
if any~/.my.cnf
- User-specific~/.mylogin.cnf
- User-specific (clients only)
/etc/my.cnf
- 全球的/etc/mysql/my.cnf
- 全球的SYSCONFDIR/my.cnf
- 全球的SYSCONFDIR
表示在构建 MySQL 时使用SYSCONFDIR
选项指定的目录CMake
。默认情况下,这是位于编译安装目录下的 etc 目录。$MYSQL_HOME/my.cnf
- 特定于服务器(仅限服务器)MYSQL_HOME
是一个环境变量,包含服务器特定my.cnf
文件所在目录的路径。如果MYSQL_HOME
未设置并且您使用该mysqld_safe
程序启动服务器,mysqld_safe
请将其设置BASEDIR
为 MySQL 基本安装目录。指定的文件(
--defaults-extra-file=path
如果有)~/.my.cnf
- 用户特定~/.mylogin.cnf
- 特定于用户(仅限客户端)
Source: Using Option Files.
来源:使用选项文件。
Note: On Unix platforms, MySQL ignores configuration files that are world-writable. This is intentional as a security measure.
注意:在 Unix 平台上,MySQL 会忽略全局可写的配置文件。这是有意作为一种安全措施。
Additionally on Mac there is a simple way to check it.
此外,在 Mac 上有一个简单的方法来检查它。
Run:
sudo fs_usage | grep my.cnf
This will report any filesystem activity in real-time related to that file.
In another Terminal, restart your MySQL/MariaDB, e.g.
brew services restart mysql
or:
brew services restart mariadb
On terminal with
fs_usage
, the proper location should be shown, e.g.15:52:22 access /usr/local/Cellar/mariadb/10.1.14/my.cnf 0.000002 sh
So if the file doesn't exist, create one.
跑:
sudo fs_usage | grep my.cnf
这将实时报告与该文件相关的任何文件系统活动。
在另一个终端,重启你的 MySQL/MariaDB,例如
brew services restart mysql
或者:
brew services restart mariadb
在带有
fs_usage
的终端上,应显示正确的位置,例如15:52:22 access /usr/local/Cellar/mariadb/10.1.14/my.cnf 0.000002 sh
因此,如果该文件不存在,请创建一个。
回答by Jeffrey Chung
I don't know which version of MySQL you're using, but here are possible locations of the my.cnf file for version 5.5 (taken from here) on Mac OS X:
我不知道您使用的是哪个版本的 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
(the file specified with--defaults-extra-file=path
, if any)~/.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
回答by Sergio Rodrigues
For MySQL 5.7 on Mac OS X El Capitan: /usr/local/mysql/etc/my.cnf
对于 Mac OS X El Capitan 上的 MySQL 5.7: /usr/local/mysql/etc/my.cnf
Copy default conf from /usr/local/mysql/support-files/my-default.cnf
从 /usr/local/mysql/support-files/my-default.cnf
回答by Gpak
If you are using macOS Sierra and the file doesn't exists, run
如果您使用的是 macOS Sierra 并且该文件不存在,请运行
mysql --help or mysql --help | grep my.cnf
mysql --help or mysql --help | grep my.cnf
to see the possible locations and loading/reading sequence of my.cnf for mysql then create my.cnf file in one of the suggested directories then add the following line
查看 my.cnf for mysql 的可能位置和加载/读取顺序,然后在建议的目录之一中创建 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
[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
You can sudo touch /{preferred-path}/my.cnf
then edit the file to add sql mode by
sudo touch /{preferred-path}/my.cnf
然后,您可以编辑该文件以添加 sql 模式
sudo nano /{preferred-path}/my.cnf
sudo nano /{preferred-path}/my.cnf
Then restart mysql, voilaah you are good to go. happy coding
然后重新启动 mysql,瞧你一切顺利。快乐编码
回答by Jpsy
The current MySQL package for Mac OS X Mavericks(mysql-5.6.17-osx10.7-x86_64 at the time of this writing) automatically creates a my.cnf during installation.
Mac OS X Mavericks的当前 MySQL 包(在撰写本文时为 mysql-5.6.17-osx10.7-x86_64)在安装过程中自动创建一个 my.cnf。
It is located at /usr/local/mysql-5.6.17-osx10.7-x86_64/my.cnf
Adapt your path according to your version.
它位于/usr/local/mysql-5.6.17-osx10.7-x86_64/my.cnf
根据您的版本调整您的路径。
回答by Datbates
So none of these things worked for me. I am using the current dmg install of mysql community server. ps shows that all of the most critical parameters normally in my.cnf are passed on the command line, and I couldn't figure out where that was coming from. After doing a full text search of my box I found it in:
所以这些东西都不适合我。我正在使用 mysql 社区服务器的当前 dmg 安装。ps 显示 my.cnf 中所有最关键的参数通常都是在命令行上传递的,我无法弄清楚这是从哪里来的。在对我的盒子进行全文搜索后,我在以下位置找到了它:
/Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
/Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
So you can either change them there, or take them out so it will actually respect the ones you have in your my.cnf wherever you decided to put it.
所以你可以在那里改变它们,或者把它们取出来,这样它就会真正尊重你在 my.cnf 中决定放置它的地方。
Enjoy!
享受!
Example of the file info found in that file:
在该文件中找到的文件信息示例:
<?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>
回答by sreimer
You can open a terminal and type locate my.cnf
您可以打开终端并输入 locate my.cnf
回答by StevenR
In mysql 5.6.22, which I installed it from Homebrew, the path of my.cnf is
在我从 Homebrew 安装的 mysql 5.6.22 中,my.cnf 的路径是
/usr/local/opt/mysql/my.cnf