mac brew 安装的mysql开机自启动

1、用brew安装的可以通过以下语句查看安装目录:

brew –prefix mysql

2、从你MySQL的安装目录下找到homebrew.mxcl.mysql.plist这个文件,然后复制到~/Library/LaunchAgents目录下,然后在终端执行以下语句即可:

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

如果没有,创建一个此文件,命名可以随意,例如mysql.plist ,键入以下内容

<?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>--user=root</string>  
     </array>    
   </dict>  
</plist>

**其中/ust/local/opt/mysql是我的mysql安装目录,替换成你自己的就可以
最后,执行以下语句**

launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

注:这里的文件名以你mysql目录下的名字,或者你自己创建时起的名字为准

附:Mac OS X的启动原理:mac固件激活,初始化硬件,加载BootX引导器。BootX加载内核与内核扩展(kext)。内核启动launchd进程。launchd根据 /System/Library/LaunchAgents, /System/Library/LaunchDaemons , /Library/LaunchDaemons,/Library/LaunchAgents , ~/Library/LaunchAgents里的plist配置,启动服务守护进程。

相关内容推荐