title: Installing MySQL and mysql gem on Snow Leopard
body: <p>It´s really a hard job figuring out how to get MySQL and mysql gem up and running on Snow Leopard 10.6.2. I followed the instructions of various posts but was not successful yet:</p>
  
  <p>I build MySQL Version 5.1.39 from source and it installed successfully. When trying to login using (mysql -u root -p) mysql returned the following error: </p>
  
  <p><code>ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)</code></p>
  
  <p>that obviously meant that the MySQL Server (mysqld) was not running.</p>
  
  <pre><code>which mysql: /usr/local/mysql/bin/mysql
  which ruby: ruby 1.8.7 (2009-04-08 patchlevel 160) [i686-darwin9])
  gem -v: 1.3.5
  mysql: Server version: 5.1.39 MySQL Community Server (GPL)
  </code></pre>
  
  <p>After a lot of googling around, I found out that</p>
  
  <ol>
  <li><p>this command can start mysqld:</p>
  
  <p><code>sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &amp;</code></p></li>
  <li><p>The Preference Pane MySQL Tool is probably broken in Mac OS X 10.5 and higher</p></li>
  <li><p>This command should install the mysql gem correctly on Snow Leopard:</p>
  
  <p><code>sudo gem uninstall mysql
  sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config</code></p></li>
  </ol>
  
  <p>It ended up that I got the following error using something like rake db:create:</p>
  
  <pre><code>dyld: lazy symbol binding failed: Symbol not found: _mysql_init 
  Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle 
  Expected in: flat namespace 
  dyld: Symbol not found: _mysql_init 
  Referenced from: /opt/local/lib/ruby/gems/1.8/gems/mysql-2.8.1/lib/mysql_api.bundle 
  Expected in: flat namespace
  </code></pre>
  
  <p>This error led me to the following post: <a href="http://cho.hapgoods.com/wordpress/?p=158" rel="nofollow noreferrer">http://cho.hapgoods.com/wordpress/?p=158</a>, that basically tells me that the Ruby Version that came together with XCode 3.0 does not work in 64bit environments and a solution could be to install the 32bit versionof MySQL.</p>
  
  <p>Any suggestions, how to proceed?</p>