升级 OS X 后,我安装的 MySQL 在启动时停止加载。
这个 walk-through on MySQL 说:
“启动项安装在系统配置文件/etc/hostconfig中增加了一个变量MYSQLCOM=-YES-,如果要禁用MySQL的自动启动,将此变量改为MYSQLCOM=-NO-。”
所以,我打开了那个文件,上面写着:
# This file is going away
AFPSERVER=-NO-
AUTHSERVER=-NO-
TIMESYNC=-NO-
QTSSERVER=-NO-
MYSQLCOM=-YES-
我假设 OSX 开发人员添加了 # This file is going away
,但我不确定。
如果是这种情况,在 OSX Yosemite 上启动 MySQL 的正确方法是什么?
这是修复它的原因:
首先,创建一个新文件:/Library/LaunchDaemons/com.mysql.mysql.plist
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true />
<key>Label</key>
<string>com.mysql.mysqld</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/mysql/bin/mysqld_safe</string>
<string>--user=mysql</string>
</array>
</dict>
</plist>
然后更新权限并将其添加到 launchctl
:
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
如果您通过 homebrew 安装 mysql,您可以让 launchd
在登录时启动 mysql:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
接受的答案无法自动启动我的 MySQL 服务器(事实上,每次我尝试在它处于活动状态时打开它时,我的首选项窗格都会崩溃系统首选项)。我按照 the MySQL 5.6 handbook 的说明进行操作,它终于又自动启动了!使用以下内容创建文件 /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist
:
<?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>--port=3306</string>
</array>
<key>WorkingDirectory</key> <string>/usr/local/mysql</string>
</dict>
</plist>
创建文件后运行以下命令:
cd /Library/LaunchDaemons
sudo chown root:wheel com.oracle.oss.mysql.mysqld.plist
sudo chmod o-w com.oracle.oss.mysql.mysqld.plist
sudo launchctl load -F com.oracle.oss.mysql.mysqld.plist
我的 Mac 在 El Capitan 上运行。 MySQL 通过 brew 安装。
mysql.server status
告诉我我有一些问题需要解决:
ERROR! MySQL is not running, but PID file exists
在 /usr/local/Cellar/mysql/x.x.x/
目录中找到 homebrew.mxcl.mysql.plist
文件并将其复制到 /Library/LaunchDaemons/
sudo cp homebrew.mxcl.mysql.plist /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
设置所有必要的权限:
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.mysql.plist
使用的部分建议,由 Justin 描述
MacMiniVault 有一个 bash script,它将为您完成此操作 - 并安装 MySQL。还有一个 article 描述了该过程。
文章中建议将脚本直接通过管道传输到终端并运行它,但由于这具有一些严重的安全隐患,最好在本地运行之前下载并检查脚本。
注意:此回复已针对有关遵循上述文章中的说明的安全影响的评论进行了重新设计。将未知来源的 shell 脚本直接传送到 bash 通常是个坏主意。另外,如果您不理解脚本或不信任作者,请不要使用它。
不定期副业成功案例分享
Startup items are a deprecated technology. Launching of daemons through this process may be removed or eliminated in a future release of OS X.
_mysql
。您可以运行dscacheutil -q user | grep mysql
来查看用户在您的系统上应该是什么。--user=my_user_name
才能使其工作。