How to Fix: Library not loaded: libmysqlclient.18.dylib

9th July, 2011 Patrick

Just installed OS X Lion and after installing RVM, Rails, and MySQL I went to got start one of my rails projects and received this great message.

/Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.3/lib/mysql2.rb:7:in `require': dlopen(/Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.3/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.18.dylib (LoadError)
  Referenced from: /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.3/lib/mysql2/mysql2.bundle
  Reason: image not found - /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.3/lib/mysql2/mysql2.bundle
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/mysql2-0.2.3/lib/mysql2.rb:7:in `<top (required)>'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `require'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `each'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:66:in `block in require'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `each'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler/runtime.rb:55:in `require'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.15/lib/bundler.rb:120:in `require'
    from /Users/patrick/Workspace/MonkeyOnCode/config/application.rb:7:in `<top (required)>'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.0/lib/rails/commands.rb:28:in `require'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.0/lib/rails/commands.rb:28:in `block in <top (required)>'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.0/lib/rails/commands.rb:27:in `tap'
    from /Users/patrick/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.0/lib/rails/commands.rb:27:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

This is simply an issue with mysql2 not being able to find the MySQL provided dynamic library. The easy way to fix this is simple add the below value to your ~/.bash_profile and you will need to source the file again or start a new terminal.

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib:$DYLD_LIBRARY_PATH

Google +1 Meet Webmaster Tools

6th July, 2011 Patrick

I find Google Webmaster tools a very helpful tool for understanding how Google is viewing your site, which includes some tools for generating robot.txt files, viewing stats and seeing errors on your site. Google also introduced Google +1 button which is similar to a facebook "Like" button. Well it looks like Google added support for the +1 Button to the Google Webmaster tools. As you can see below you can view impressions, how many clicks, and where it originated.

Google Webmaster - Google 1+

Rails Wizard

28th June, 2011 Patrick

I just ran across nifty little tool called RailsWizard which I am going to start using to bootstrap my rails projects. You can quickly select which frameworks you want to include, and it will disable exclusive packages. Once your ready, you simply select "Finish" and it provides you with a rails command that uses a template that will be downloaded from the RailsWizard and will start the install process. I would say for most of my projects A single template will work for most but for when you want to work outside to box this makes it quick and simple.

How to Initialize Lists for Unit Tests

31st January, 2011 Patrick

I like clean simple condensed code, esecially when it comes to tests. I really do not like seeding the lists this way

List<String> values = new ArrayList<String>();


This method requires a lot of keyboard interaction if you do not use your mouse. Having to navigate lines of code with a keyboard can interrupt ones flow. Or you can use the mouse to highlight, copy and paste but who likes touching their mouse when coding.

So i started intializing my list like this for quite some time.

List<String> values = new ArrayList<String>(){{


If you are not familier with double brace initializers then this code can be difficult to read and even can seem invalid to some. But this solved the problem by reducing my keyboard interaction so I used it.

Just recently I started using this method.

String[] values = {"test", "foo", "bar"};

This really solved my problem with reducing my keyboard interaction even more than before and it also made the code easy to read and condensed.

PHP MVC Frameworks

31st January, 2011 Patrick

I first was introduced to object oriented programming via PHP. I worked as a PHP developer for about 3 years between AT&T and Lifelock. I have since moved from PHP to Java for my professional career. As a small business owner that develops web sites for other small business means that I have to touch a lot of PHP code. When I was developing at AT&T two PHP MVC frameworks were introduced, Zend Framework and CakePHP. I remember looking into both of them when the came out and considered using them on my project. Since then I have not had to many opportunities or need to use a PHP web framework.

I recently decided that it would be best to know at least one PHP framework so I chose to start with Zend Framework. It didn't take long for me to give up on it. It was specifically when I got to the part about naming conventions of files. This alone was not my only issue but there was a lack of intuitive development about the framework. As a Ruby on Rails fan I know thing can be much easier. So I have turned my back on Zend Framework for now and going to give try CakePHP.

Older Posts