On Mac we use the [Homebrew] package management tool (http://brew.sh/index_zh-cn.html) to install and manage development kits such as MySQL, PHP, and Redis. Only one command is needed
install mysql
It installs all the packages into the /usr/local/Cellar/
directory and soft-connects the files to the/usr/local/
After the installation is complete you need to go to /usr/local/Cellar/mysql/5.6.26/bin
the next to find MySQL to boot. However, if the terminal is switched off, the MySQL service will also be closed so that it always occupies a terminal window.
Mac OS Start-up mode
launchd
is the key process for initializing the system environment under MAC OS, which is the first process that starts in the OS environment after the kernel is loaded successfully. It is very simple to configure the self-launcher in this way, only one plist file is required, and the directory where the plist file exists is:
- Launchdaemons
~/Library/LaunchDaemons
User run plist (program) before landing
- Launchagents
~/Library/LaunchAgents
Run the appropriate plist (program) after the user logs in
You need .plist
a file to specify a program to boot.
The following is an example of a. plist configuration file for boot startup:
<?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" ><Plistversion="1.0" ><Dict><Key>label</Key><String>org.mongodb.mongod</String><Key>programarguments</Key><Array><String>/usr/local/mongodb-2.0.3/bin/mongod</String><String>run</String><String>--config</String><String>/usr/local/mongodb-2.0.3/mongod.conf</String></Array><Key>runatload</Key><True/><Key>keepalive</Key><True/><Key>workingdirectory</Key><string>/usr/local/mongodb-2.0.3</string> <key>standarderrorpath</key> <string>/usr/ Local/mongodb-2.0.3/log/error.log</string> <key>standardoutpath</key > <string>/usr/local/mongodb-2.0.3/log/mongo.log</string> </dict ></plist>
How to write a. plist file
The brew has been written for you when you install .plist
it. You just need brew info mysql
to run to see the help information.
brew info mysql
<script type= "Text/javascript" src= "Https://asciinema.org/a/44624.js" id= "asciicast-44624" Async></script >
At this point the terminal will display the following information:
CaveatsWe‘ve installed your MySQL database without a root password. To secure it run: mysql_secure_installation To connect run: mysql -uroot 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 Or, if you don‘t want/need launchctl, you can just run: mysql.server start
Follow the prompts to ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
add MySQL to the login startup list
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
or start MySQL nowlaunchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
After booting, you can shut down the terminal and MySQL will run in the background.
Wen/lixiaohao (author of Jane's book)
Original link: http://www.jianshu.com/p/e73978416920
New Mac Boot Mysql/mongodb/redis and other services