Resolving the MySQL Homebrew Install Issue

Posted: November 30th, 2010 | Author: | Filed under: posts | Tags: , , | 6 Comments »

We switched from using MacPorts to Homebrew for package management on our Mac OS X development machines. Recently, when building two machines and using brew to install MySQL on them, we ran into an issue where MySQL would only partially install and we’d get a mysql database with an empty user table. This was with mysql-5.1.52:

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from user;
Empty set (0.00 sec)

We tried a couple of things to solve this, but were not able to come up with a workable way to insert a root user, as you can’t create users when running with the –skip-grant-tables option.

I also tried the binary download from MySQL.com and hit the same snag.

After a couple of rebuilds and testing with a fresh install of Snow Leopard, we traced the issue back to the following error message from the MySQL setup script:

$mysql_install_db
Installing MySQL system tables...
ERROR: 1049  Unknown database 'mysql'
101121 19:21:38 [ERROR] Aborting
101121 19:21:38 [Note] ./bin/mysqld: Shutdown complete
Installation of system tables failed!  Examine the logs in
./data for more information.
"¦

Error 1049 proved to be the key to solving this. It led me to this MySQL bug report, which discusses that this error can be generated when the default temporary directory doesn’t exist.

Passing the /tmp temporary directory to mysql_install_db as a param seems to resolve error 1049 and allow us to get the default mysql system database setup with a working root user.

Most of the instructions for installing MySQL with Homebrew don’t mention any additional params needed, which leads me to believe this is something recent in the recent builds of MySQL. We didn’t have this issue when installing MySQL on our other Snow Leopard machines (which have 5.1.49). However, this is the sequence of commands that we found that worked for us – hopefully, this will help others hitting similar snags:

brew install mysql
mysql_install_db --user=mysql --tmpdir=/tmp
mysql.server start
#server must be running first
mysql_secure_installation

  • Mark Learst

    Rob you ROCK!!! I spent days figuring out why my “brew install mysql” was seeming to fall into no mans land when trying to access and setup mysql. You instructions solved my issue in minutes!

  • http://blog.shedd.us Robert Shedd

    Glad it helped, Mark! Thanks for the comment to let me know this was useful!

  • http://twitter.com/chrys Chris Waigl

    Thank you — I came to your post after half a day fiddling with exactly this problem. I had kinda resolved it by creating a root user via the MySQL Workbench, but there were still some error messages such as when trying to shut down the server. I’m grateful for your troubleshooting & sharing of the results.

  • http://blog.shedd.us Robert Shedd

    Thanks for letting me know the post was helpful, Chris! It’s good to know that it’s possible to create a root user via MySQL Workbench, too.

  • http://blog.shedd.us Robert Shedd

    Because it sounds like others are running into these issues, I’ve gone ahead and forked the Homebrew repo and pushed a change to help clarify these additional options.

    Commits here: https://github.com/shedd/homebrew/commits/tmpdirectory_resolution

    Hope this helps others get out of mysql_install_db no-man’s land!

  • http://blog.shedd.us Robert Shedd

    Pull request to Homebrew master created: https://github.com/mxcl/homebrew/pull/4357