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.
1 | sudo port install mysql5 +server |
Next up, create the initial databases used by MySQL.
1 | sudo /opt/local/lib/mysql5/bin/mysql_install_db --user=mysql |
Configure MySQL to start at system start up.
1 | sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist |
Start MySQL.
1 | sudo /opt/local/bin/mysqld_safe5 & |
You can always stop the service manually as well:
1 | mysqladmin5 -u root -p shutdown |
Confirm that that MySQL is running.
1 | 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.
1 | 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.
1 | mysql5 -u root -p |
At the prompt, run the command.
1 | status; |
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.
1 2 | 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!
Hi, Matthew:
thanx a lot for this info
Before running the command:
sudo /opt/local/lib/mysql5/bin/mysql_install_db –user=mysql
You need to run the commands:
sudo chown -R mysql:mysql /opt/local/var/db/mysql5
sudo chmod u+rwx,go= /opt/local/var/db/mysql5
This will prevent the error:
ERROR: 1004 Can't create file '/var/tmp/#sql2d4_1_0.frm' (errno: 9)
Unlike other posts that take a *long* time to get to the point by talking about meaningless stuff that you don't really want to know about, your post gets right to the point! Thank you.
Neat … doesn't work on Leopard though … why? you left out the my.cnf and plist and … permissions issues etc….