MySQL on Lion with Homebrew

200px MySQL

This was non-obvious to me, so I’m documenting it here.

There are several ways you can get MySQL up and running on Mac OS X Lion (see for example Rob Allen’s Setting up PHP & MySQL on OS X 10.7 Lion, StackOverflow’s Getting MySQL work on OSX 10.7 Lion, or Installation of MySQL server on Mac OS X Lion). However, if you’re already a Homebrew user, perhaps the easiest and best-integrated route is to install the mysql recipe for homebrew:

brew install mysql

Unfortunately, this doesn’t give you instant fame, fortune or a working mysql install: there’s also some post-install configuration required, which I missed. For more information tailored to your install, type:

brew info mysql

The extra steps boil down to running mysql_install_db and then mysql.server start.

~

One thing that puzzles me about a lot of the mysql documentation (and in fairness other similar software) is the insistence of providing post-install configuration instructions like mysqladmin -u root password 'new-password'. This is such a bad idea, as it means your new password is stored in your console history. For fun, try grep password ~/.bash_history and boggle at the number of times your password is listed in plain text.

These command-line utilities are all perfectly able to prompt you for the password text; entering mysqladmin -u root password or mysqladmin -u root -p password will result in a password prompt, which prevents the password showing up in your history. It makes sense because you never know who will be looking over your shoulder as you scroll back through your command history.

~

One last thing: you might like to read Removing MySQL from OSX Lion if you’d previously installed it some other way. Some day Apple will provide an uninstaller, but until then…

This entry was posted in Computing, Planet and tagged , , , , , , , , , . Bookmark the permalink.

Comments are closed.