Posts tagged homebrew

All posts

Stop MySQL being loaded on OS X boot

Right now I find myself working on a porject that uses MongoDB, and sometimes I work on projects with PostgreSQL and other times on projects that use MySQL. The difference is that I have to manually load both MongoDB (mongod) and PostgreSQL (I use the Heroku app) when I want to use them, but MySQL is loaded in my system by default.

Thinking on an all-or-none solution, I decided to convert MySQL in a service run on demand, instead of a resident one. I have installed MariaDB via Homebrew, so:

  ➜  julitrows.gitlab.com git:(master) ✗ brew info mariadb
  mariadb: stable 5.5.34, devel 10.0.7
  http://mariadb.org/
  ...
  **BLAH BLAH BLAH **
  ...
  To load mariadb after an update
      launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
      launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

So the second to last line is what we are looking for. By running:

launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist

We’ll remove mysql from being run at startup.

And when we want to use mysql, just do mysql.server start, and mysql.server stop

Easy!


Clean unneeded dependencies on Homebrew

Let’s say you’ve uninstalled a formula with Hombrebrew that it’s no longer needed. Homebrew won’t clean the associated dependencies that are no longer needed. You can do this by running:

$ brew rm $(join <(brew leaves) <(brew deps <FORMULA>))

This calls for the formula dependencies and does a join with the installed packages that are not dependencies of other packages, and uninstall the resulting list of packages.

CAVEAT EMPTOR: This method uninstalled Qt from my computer, and I needed it for Capybara. This happened because brew only takes into account dependencies of programs installed with brew. Any dependency from outside brew is ignored.


Multiple Installations Mayhem: MySQL

While trying to build and install PHP 5.4 in a OS X 10.7.5 in order to test Laravel, I found myself updating several things with Homebrew. It seems that one of the things updated was my brew installation of MySQL.

The thing is that later, I tried to boot the Rails console for a project and it puked this fearsome line:

~/.rvm/gems/<gemset>/gems/activesupport-2.3.17/lib/active_support/dependencies.rb:466:in
    `load_missing_constant':NameError: uninitialized constant MysqlCompat::MysqlRes

As delicate as installing MySQL in Mac OS X and getting it to work is, I knew this was a bad omen. Yes. I couldn’t make any query using the rails console.

So, after checking the Internet, the first probable cause is that after changing the MySQL installation you would need to rebuild the mysql gem. So, after checking ‘which MySQL’ was in use, I reinstalled the gem with some options:

env ARCHFLAGS="-arch x86_64" \
gem install mysql -v=2.8.1 --with-mysql-config=/usr/local/mysql/bin/mysql_config

Everything went smoothly, but I had the same error when firing up the console. Damn. The next thing I found about it was about the libmysqlclient not being installed or found. But locate libmysqlclient gave me three different paths… so it had to be about the library not being visible. After researching, the library is usually looked for in the $DYLD_LIBRARY_PATH. Set the proper path in your .bash_profile (something along /user/local/mysql/lib) and you’ll get going.