There comes a time in every Rails developers life that they need to work with MySQL. Often this means that your development comes to a screeching halt as you wade through the various options for getting MySQL installed on your Mac.
This guide won’t help you install it anywhere else… because I am a zealot and I don’t care how to install it anywhere else.
Install MySQL using macports, go get a coffee while this runs its course.
sudo port install mysql5 +server
Next up, create the initial databases used by MySQL.
sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql
Configure MySQL to start at system start up.
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo /opt/local/bin/mysqld_safe5 &
You can always stop the service manually as well:
mysqladmin5 -u root -p shutdown
Confirm that that MySQL is running.
mysqladmin5 -u root -p ping
Just hit enter at the password prompt, as it is blank. We are about to change that.
Secure your server.
mysqladmin5 -u root password [your password goes here]
At this point you should have your MySQL server up and running. However, your Rails project may complain about not being able to find the socket file. You can find that using the ‘status’ command.
First log into MySQL.
mysql5 -u root -p
At the prompt, run the command.
In the output you will see an entry listing the socket being used by MySQL. You can use this in the database.yml file.
And finally, I really don’t like typing that ’5′ after all the commands… I can’t explain it, it just upsets me. So I like to create a symbolic link for the mysql5 and mysqladmin5 commands.
sudo ln -s /opt/local/bin/mysql5 /opt/local/bin/mysql sudo ln -s /opt/local/bin/mysqladmin5 /opt/local/bin/mysqladmin
That should get you coding again against a MySQL database!