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
Tags: development environment, mac-osx, mysql

Robert Shedd is currently VP of Product and Technology for Three Screen Games, a Philadelphia-based social gaming startup, which recently launched 








