title: MySQL 5.5 on Lion not working
body: <p>I've installed MySQL 5.5 via the disk image on Mac OS X 10.7. I've also added <code>/usr/local/mysql/bin</code> to my path in <code>.bash_profile</code>.</p>
  
  <p><code>which mysql</code> returns <code>/usr/local/mysql/bin/mysql</code></p>
  
  <p>However, I can't seem to get the server running, no matter whatever I try.</p>
  
  <p><code>mysql -u root</code> returns:</p>
  
  <pre><code>ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
  </code></pre>
  
  <p><code>sudo /usr/local/mysql/bin/mysqld_safe</code> starts and then immediately stops the daemon:</p>
  
  <pre><code>120130 23:18:57 mysqld_safe Logging to '/usr/local/mysql/data/Bryans-Macbook-Pro.local.err'.
  120130 23:18:57 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
  120130 23:18:59 mysqld_safe mysqld from pid file /usr/local/mysql/data/Bryans-Macbook-Pro.local.pid ended
  </code></pre>
  
  <p>I feel that I have tried every possible solution that can be found, and I am out of ideas now. I've even tried installing an older version of MySQL (5.1) and got the same results and efforts invain.</p>
  
  <p><strong>FURTHER INFORMATION</strong></p>
  
  <p>Running <code>mysqld</code> results in:</p>
  
  <pre><code>$ mysqld
  120209  0:02:23 [Warning] Setting lower_case_table_names=2 because file system for /usr/local/mysql-5.5.20-osx10.6-x86_64/data/ is case insensitive
  120209  0:02:23 [Note] Plugin 'FEDERATED' is disabled.
  mysqld: Table 'mysql.plugin' doesn't exist
  120209  0:02:23 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
  120209  0:02:23 InnoDB: The InnoDB memory heap is disabled
  120209  0:02:23 InnoDB: Mutexes and rw_locks use GCC atomic builtins
  120209  0:02:23 InnoDB: Compressed tables use zlib 1.2.3
  120209  0:02:23 InnoDB: Initializing buffer pool, size = 128.0M
  120209  0:02:23 InnoDB: Completed initialization of buffer pool
  120209  0:02:23 InnoDB: highest supported file format is Barracuda.
  120209  0:02:23 InnoDB: 1.1.8 started; log sequence number 1595675
  120209  0:02:23 [ERROR] mysqld: unknown option '--skip-locking'
  120209  0:02:23 [ERROR] Aborting
  
  120209  0:02:23  InnoDB: Starting shutdown...
  120209  0:02:24  InnoDB: Shutdown completed; log sequence number 1595675
  120209  0:02:24 [Note] mysqld: Shutdown complete
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Well, I removed mysql completely from my system, re-installed an older version (5.1), and it is actually starting up now. However, I still can't run <code>rails server</code>. I get the following error:</p>
  
  <pre><code>/Users/bricker/.rvm/gems/ruby-1.8.7-p352/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle: dlopen(/Users/bricker/.rvm/gems/ruby-1.8.7-p352/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle, 9): Library not loaded: /opt/local/lib/mysql5/mysql/libmysqlclient_r.16.dylib (LoadError)
  </code></pre>
  
  <p>So, I've run this command:</p>
  
  <pre><code>sudo install_name_tool -change libmysqlclient_r.16.dylib /opt/local/lib/mysql5/mysql/libmysqlclient_r.16.dylib ~/.rvm/gems/ruby-1.8.7-p352/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle
  </code></pre>
  
  <p>But still receive the error when attempting to start the 'rails server'.</p>
  
  <p><strong>UPDATE 2</strong></p>
  
  <p>Okay, final update: After everything, reinstalling mysql numerous times, seeing all these errors - it turns out that perhaps the original problem was a conflict between gems <code>mysql2-0.2.7</code> and <code>mysql2-0.3.11</code>. To ultimately fix the problem:</p>
  
  <ol>
  <li><p>Removed all mysql-related files from my system (see bash script below)</p></li>
  <li><p>Installed MySQL 5.1.61 (64-bit) from the Disk Image provided on the MySQL website</p></li>
  <li><p>Ran the following lines:</p></li>
  </ol>
  
  <p><code>sudo install_name_tool -change libmysqlclient_r.16.dylib /opt/local/lib/mysql5/mysql/libmysqlclient_r.16.dylib ~/.rvm/gems/ruby-1.8.7-p352/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle</code></p>
  
  <p><code>sudo install_name_tool -change libmysqlclient.16.dylib /usr/local/mysql/lib/libmysqlclient.16.dylib ~/.rvm/gems/ruby-1.8.7-p352/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle</code></p>
  
  <ol>
  <li>ran <code>gem uninstall mysql2</code>, and selected the version <code>0.3.11</code> - the only version left on this RVM section is <code>mysql2-0.2.7</code>.</li>
  </ol>
  
  <p>Now everything seems to be working! Thanks again for all the help.</p>
  
  <p><strong>Bash script to remove mysql-related files from Mac OS X (10.6 &amp; 10.7).</strong></p>
  
  <pre><code>#!/bin/bash
  sudo rm /usr/local/mysql
  sudo rm -rf /usr/local/mysql*
  sudo rm -rf /Library/StartupItems/MySQLCOM
  sudo rm -rf /Library/PreferencePanes/My*
  sudo rm -rf ~/Library/PreferencePanes/My*
  sudo rm -rf /Library/Receipts/mysql*
  sudo rm -rf /Library/Receipts/MySQL*
  sudo rm -rf /var/db/receipts/com.mysql.*
  echo "Done."
  </code></pre>
  
  <p>Copy into <code>remove-mysql.sh</code>, make it executable (<code>chmod +x remove-mysql.sh</code>), and run it.</p>