Currently I start and stop mysql with the following command
sudo /usr/local/mysql/support-files/mysql.server start
sudo /usr/local/mysql/support-files/mysql.server stop
It is quite a long command to remember. How can I set it up so that I can start and stop it with a single command. Something like.
sudo mysql-server start
I am thinking I would need to crete a symbolic link somewhere for this to work? Also one last option; how can I make it so that it runs on bootup by default?
Best Answer
Just create an alias in your ~/.bash_profile or ~/.profile file.
Check with
ls -la0 ~/
if one of the files already exist, else create one with:After opening .bash_profile with
nano ~/.bash_profile
add the lines:write the file to disk with ctrlO and exit nano with ctrlX.
Then enter:
In the future you just have to enter
or
to start or stop mysql after entering your password.
A shorter alias like
iwanttostartmysqlnow
works also. Even really, really short ones are possible likestm
(= start mysql) orspm
(= stop mysql). They mustn't collide with other aliases or valid commands though. The shortest I have found - and easy to remember - are1
to start and0
to stop mysql. ;-)To answer your second question:
If you have installed the latest MySQL from Oracle a launch daemon should have been installed in /Library/LaunchDaemons already.
If you have installed another mysql package (e.g. homebrew) you may use the example here and adapt it.
Slightly modified example:
Save the XML as a file named /Library/LaunchDaemons/com.mysql.mysql.plist
Adjust the file permissions using the Apple recommended owner "root", owning group "wheel", and file permissions "644"
Enable this new MySQL service with: