I would like to auto start the MySQL server on startup. This was possible in Mavericks but seems to be not working on Yosemite.
我想在啟動時自動啟動MySQL服務器。這在小牛隊是有可能的,但似乎並沒有在約塞米蒂。
edit: seems this works with El Capitan as well
編輯:看來這與El Capitan也有關系。
7 个解决方案
#1
143
@dcc was very close. This is how MySQL autostarts again on Yosemite:
@dcc非常接近。這是MySQL在Yosemite上的自動啟動方式:
The com.mysql.mysql.plist in /Library/LaunchDaemons:
com.mysql.mysql。plist /圖書館/ 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!
如果你有任何增加,請分享以下!
#2
13
I followed @revaxarts directions and upon trying to execute the command
我按照@revaxarts的指示執行命令
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
was given the error:
給出了誤差:
/Library/LaunchDaemons/com.mysql.mysql.plist: Invalid property list
/圖書館/ LaunchDaemons / com.mysql.mysql。plist:無效的屬性列表
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.
在我撓頭了一會兒之后,我發現在頂部刪除DOCTYPE DTD聲明后,錯誤消失了,重新啟動mySQL服務器時,確實正在運行。
So, my XML looks like this:
我的XML是這樣的:
KeepAlive
Label
com.mysql.mysqld
ProgramArguments
/usr/local/mysql/bin/mysqld_safe
--user=mysql
#3
8
If you installed mysql with homebrew, you can get instructions on how to autostart it by typing brew info mysql.
如果你用homebrew安裝了mysql,你可以通過輸入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
#4
2
Create /Library/LaunchDaemons/com.mysql.mysql.plist and save it with the following plist:
創建/圖書館/ LaunchDaemons / com.mysql.mysql。plist保存如下plist:
KeepAlive
Label
com.mysql.mysqld
ProgramArguments
/usr/local/mysql/bin/mysqld_safe
--user=mysql
Then load the newly created plist file
然后加載新創建的plist文件。
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
#5
2
This article help me resolve the issue with invalid error. Corrected plist I used below.
這篇文章幫助我用無效的錯誤來解決這個問題。我下面使用的修正plist。
如何知道哪行plist文件是不正確的
KeepAlive
Label
com.mysql.mysqld
ProgramArguments
/usr/local/mysql/bin/mysqld_safe
--user=mysql
#6
1
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:
沒有一個提供的答案可以自動啟動我的MySQL服務器。我按照MySQL 5.6手冊上的說明,它終於又自動啟動了!創建文件/圖書館/ LaunchDaemons / com.oracle.oss.mysql.mysqld。plist有以下內容:
/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
0
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.
當我使用前面回答中建議的plist時,我將系統的用戶更改為_mysql,但是MySQL首選項窗格中的“停止MySQL服務器”按鈕不再工作。KeepAlive鍵將導致在按下Stop按鈕后立即再次啟動進程。我使用了關鍵的RunAtLoad來使它在重新啟動時啟動,但是允許窗格中的按鈕繼續工作。
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
現在,MySQL在重新啟動時啟動,但是系統首選項中的MySQL窗格仍然有效。我在運行El Capitan, 10.11.2