长话短说,您需要创建启动文件。因此,从终端:
sudo vi /Library/LaunchDaemons/com.mysql.mysql.plist
(如果您不熟悉vi,请按i开始插入文本)
这应该是文件的内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<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>
</array>
</dict>
</plist>
按esc再: wq!enter
然后,您需要授予文件正确的权限,并将其设置为在启动时加载。
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
就是这样。