最佳答案
If you installed mysql with homebrew, you can get instructions on how to autostart it by typing brew info mysql.
For example, the output on my machine is:
To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
参考答案2
Create /Library/LaunchDaemons/com.mysql.mysql.plist and save it with the following plist:
KeepAlive
Label
com.mysql.mysqld
ProgramArguments
/usr/local/mysql/bin/mysqld_safe
--user=mysql
Then load the newly created plist file
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
参考答案3
This article help me resolve the issue with invalid error. Corrected plist I used below.
KeepAlive
Label
com.mysql.mysqld
ProgramArguments
/usr/local/mysql/bin/mysqld_safe
--user=mysql
参考答案4
@dcc was very close. This is how MySQL autostarts again on Yosemite:
The com.mysql.mysql.plist in /Library/LaunchDaemons:
KeepAlive
Label
com.mysql.mysqld
ProgramArguments
/usr/local/mysql/bin/mysqld_safe
--user=mysql
Additionally I've changed the permissions based on this answer
sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
Finally I run this command
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
If you have any addition please share below!
参考答案5
I followed @revaxarts directions and upon trying to execute the command
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
was given the error:
/Library/LaunchDaemons/com.mysql.mysql.plist: Invalid property list
After scratching my head for a minute I found that removing the DOCTYPE DTD declaration at the top made the error go away and upon restart mySQL server is, indeed, running.
So, my XML looks like this:
KeepAlive
Label
com.mysql.mysqld
ProgramArguments
/usr/local/mysql/bin/mysqld_safe
--user=mysql
参考答案6
None of the other provided answers worked to auto-start my MySQL server. I followed the instructions from the MySQL 5.6 handbook and it finally auto-starts again! Create the file /Library/LaunchDaemons/com.oracle.oss.mysql.mysqld.plist with the following content:
/p>
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
Labelcom.oracle.oss.mysql.mysqld
ProcessTypeInteractive
Disabled
RunAtLoad
KeepAlive
SessionCreate
LaunchOnlyOnce
UserName_mysql
GroupName_mysql
ExitTimeOut600
Program/usr/local/mysql/bin/mysqld
ProgramArguments
/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
--port=3306
WorkingDirectory/usr/local/mysql
And run the following commands after creating the file:
cd /Library/LaunchDaemons
sudo launchctl load -F com.oracle.oss.mysql.mysqld.plist
参考答案7
When I used the plist suggested in earlier answers, I changed the user to _mysql for my system, but the "Stop MySQL Server" button in the MySQL preference pane no longer worked. The KeepAlive key will cause the process to launch again immediately after the Stop button is pressed. I used the key RunAtLoad to get it to just start on reboot, but allow the button in the pane to continue working.
RunAtLoad
Label
com.mysql.mysqld
ProgramArguments
/usr/local/mysql/bin/mysqld_safe
--user=_mysql
Then, as in the other answers, ran:
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
Now, MySQL launches on restart, but the MySQL pane in System Preferences still works.
I'm running El Capitan, 10.11.2