As I mentioned in a previous post, I’ve just received a new Macbook Air and I continued setting up my development environment. After setting up Apache, I moved on to MySQL and I was a little bit disoriented.
This guide is a note to my future self on how I did it and also to others out there who may be on the verge of getting lost (or worse, frustrated).
I downloaded MySQL Server 5.6 (Community Version) from the MySQL website ( I needed to sign in with my Oracle ID ). After downloading, I ran the installer and MySQL was installed. The README suggests creating aliases for mysql and mysqladmin . However there are other commands that are helpful such as mysqldump . Instead, I updated my path to include /usr/local/mysql/bin
You will need to open a new Terminal window or run the command above for your path to update.
You can start the server and confirm that your MySQL installation is working fine by running this:
shell> bin/mysqld --user=mysql
But that’s not how you want to setup your database server, is it? Having to start and restart manually anytime you need the database server. You’d want to install it as a service that starts and stops when you startup and shutdown your Macbook.
To install as a service, you can follow this link. In case the information is no longer available, I’ve copied the information below:
OS X uses launch daemons to automatically start, stop, and manage processes and applications such as MySQL. Using launch daemons is recommended over startup items on OS X.Note
OS X 10.4 deprecated startup items in favour of launchd daemons, and as of OS X 10.10 (Yosemite), startup items do not function. For these reasons, using launchd daemons is preferred over startup items.
Here is an example launchd file that starts MySQL:<?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</string> <string>--user=mysql</string> </array> </dict> </plist>
Adjust the ProgramArguments array according to your system, as for example your path to mysqld might be different. After making the proper adjustments, do the following:
- 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”shell> sudo chown root:wheel /Library/LaunchDaemons/com.mysql.mysql.plist shell> sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysql.plist
- Enable this new MySQL serviceshell> sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysql.plist
The MySQL daemon is now running, and automatically starts when your system is rebooted.
This is the post that led me on the path to this solution.